Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the height of the cursor same with the height of text in UITextField?

I have UITextField with too long cursor(the cursor for "123123" in the following image)

enter image description here

How to make the height of the cursor same with the height of text?

like image 959
jybsuper Avatar asked Mar 02 '17 04:03

jybsuper


1 Answers

I accidentally stumbled across this question and even though it is a little old I feel compelled to answer it since the accepted answer actually isn't correct.

You can indeed change the height (or width) of the cursor. Just subclass the UITextField and override this method:

- (CGRect)caretRectForPosition:(UITextPosition *)position {
    CGRect rect = [super caretRectForPosition:position];
    rect.size.height = 42;
    return rect;
}
like image 121
pajevic Avatar answered Oct 25 '22 23:10

pajevic