开发者

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 开发者_如何学Cthis problem and achieve correct vertical alignment for input text?


[txtLogin setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜