CaptainCOOLGUY
CaptainCOOLGUY

Reputation: 1161

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)

Upvotes: 9

Views: 3071

Answers (1)

CaptainCOOLGUY
CaptainCOOLGUY

Reputation: 1161

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

Upvotes: 18

Related Questions