I am just using a UITextField
and the problem is the text in the UITextField
do not appears at the center.It is placed at the top position of my textField.Is there any default settings that i am missing out.
thanks in advance.
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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With