UITextField text not appearing at the center

For swift

To align vertically use

textField.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center 

To align horizontally use

quantity.textAlignment = NSTextAlignment.center

Constant UITextAlignmentCenter is now deprecated as of iOS6 and above.

You should use:

textField.textAlignment = NSTextAlignmentCenter;

Swift 4:

// vertical alignment
textField.contentVerticalAlignment = .center

// horizontal alignment
textField.textAlignment = .center

For vertical alignment:

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

Centered both vertically and horizontally:

theTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
theTextField.textAlignment = NSTextAlignmentCenter;

Centered within the parent container:

YourTextFieldName.center = parentViewField.center;