jybsuper
jybsuper

Reputation: 179

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?

Upvotes: 7

Views: 7116

Answers (4)

awaik
awaik

Reputation: 12345

in 2021 we have properties

TextFormField(
cursorHeight: 13,
cursorColor: Colors.black)

Upvotes: -1

pajevic
pajevic

Reputation: 4667

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;
}

Upvotes: 17

Anbu.Karthik
Anbu.Karthik

Reputation: 82756

we can't change the cursor height , but we can do some trick , select your textfield and change your textfield border style as UITextBorderStyleNone

you get the out put as

enter image description here

there after increase the font size of your textfield whatever you want , then you get the output as

enter image description here

Upvotes: 0

Dilip Jangid
Dilip Jangid

Reputation: 774

Suppose your UITextField name is uiTextField. To set font size add the code below

_uITextField.font = UIFont.systemFont(ofSize: 10)

Upvotes: 0

Related Questions