Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView not changing NSTextAlignment Property

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)

like image 349
CaptainCOOLGUY Avatar asked Jan 01 '15 16:01

CaptainCOOLGUY


1 Answers

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
like image 177
CaptainCOOLGUY Avatar answered Oct 26 '22 22:10

CaptainCOOLGUY