Label Alignment in iOS 6 - UITextAlignment deprecated

Viewed 89928

Seems like UITextAlignmentCenter is deprecated in iOS 6.

I still use it and works well, but it gives a warning.

How can I fix this?

label.textAlignment = UITextAlignmentCenter;

Thanks.

11 Answers

Swift 3:

label.textAlignment = NSTextAlignment.center

For Swift 5+ use:

yourLabel.textAlignment = .center

where You can set:

public enum NSTextAlignment : Int {
    case left = 0 // Visually left aligned
    case center = 1 // Visually centered
    case right = 2 // Visually right aligned
    case justified = 3 // Fully-justified. The last line in a paragraph is natural-aligned.
    case natural = 4 // Indicates the default alignment for script 
}
Related