UITextView does not change NSTextAlignment property

self.descriptionTextView.textAlignment = NSTextAlignment.Center
        println(self.descriptionTextView.textAlignment.rawValue)

      

writes

4

which indicates the default textAlignment value (NSTextAlignment.Natural).

I create a UITextView in a storyboard and manually set the alignment to Center using also the button on the right side.

The text continues to flow from the left side when the application starts.

Does anyone know why this is happening?

(I am using the latest version of XCode and it doesn't seem like using a UITextField)

+3


source to share


1 answer


Unlike UITextField, you cannot set textAlignment before editing text for UITextView. Setting the text property after setting the alignment was a problem.

Make sure to set the text, then align like this:



self.descriptionTextView.text = ""
self.descriptionTextView.textAlignment = NSTextAlignment.Center

      

+6


source







All Articles