How to center UITextField text in Swift

You would want to write it like this:

myUITextObject.textAlignment = .center

(Edited to change from .Center to .center)


What you're looking for is the textAlignment property; try this:

myUITextObject.textAlignment = NSTextAlignmentCenter;


Another way to do it, is by using the storyboard.

In fact there is a Vertical and Horizontal Control that you can use for align your element inside the UITextField. In the case above that align the text to the top left:

enter image description here

Hope it helps,