Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField: Make it higher and position input text vertically centered

The default height of a UITextField with border style UITextBorderStyleRoundedRect is 31px. For an iPad App, I'd like to make a UITextField with a height of 60px and position the text vertically centered so that it looks good (by default the text is drawn only a few pixel below the top border of the UITextField).

If i do the following...

UITextField *txtLogin = [[UITextField alloc] initWithFrame:CGRectMake(200,200,300,60)];
txtLogin.borderStyle = UITextBorderStyleRoundedRect;

...the result looks like this: http://grab.by/6jRc

As you can see, the input text is not vertically centered. I tried to find a solution and found out that I just have to inherit my own custom class from UITextField and override the - (CGRect)textRectForBounds:(CGRect)bounds method. However, this method is never called and according to this link there is a bug in Apple's API. Therefore I'm looking for alternatives that work.

What would be a good solution to solve this problem and achieve correct vertical alignment for input text?

like image 998
kiteloop Avatar asked Sep 10 '10 09:09

kiteloop


1 Answers

[txtLogin setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

like image 117
marfastic Avatar answered Nov 03 '22 01:11

marfastic