How do I vertically center UITextField Text?

Joey picture Joey · Mar 26, 2011 · Viewed 66.2k times · Source

I am simply instantiating a UITextField and noticing that the text doesn't center vertically. Instead, it is flush with the top of my button, which I find kind of odd since I would expect the default to center it vertically. How can I center it vertically, or is there some default setting that I am missing?

Answer

Roger picture Roger · Mar 26, 2011
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

In swift use:

textField.contentVerticalAlignment = UIControlContentVerticalAlignment.center