self.descriptionTextView.textAlignment = NSTextAlignment.Center
println(self.descriptionTextView.textAlignment.rawValue)
writes
4
which indicates the default textAlignment value (NSTextAlignment.Natural).
I create the UITextView in storyboard and manually set the alignment to Center using the button on the right side there as well.
The text continues to be coming from the left side when I run the app.
Anybody know why this is occurring?
(I am using the latest version of XCode and this doesn't seem to occur when using UITextField)
Unlike a UITextField, you cannot set textAlignment before editing the text for a UITextView. Setting the text property after setting the alignment was the issue.
Be sure to set the text, then alignment afterward as follows:
self.descriptionTextView.text = ""
self.descriptionTextView.textAlignment = NSTextAlignment.Center
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