Swift UILabel text alignment

I quickly create my UILabel:

let label = UILabel(frame: CGRect( x: 50, y: 50, width: 100, height: 50)) 
Settings Properties

seem easy:

 label.textColor = UIColor.redColor() 

How to implement enumeration types such as textAlignment? In Objective C, it was

 label.textAlignment = NSTextAlignmentCenter; 

but quickly it does not work.

+50
enums uilabel swift
Jun 04 '14 at 9:53 on
source share
3 answers

Now this is enum s.

You can do:

 label.textAlignment = NSTextAlignment.Center; 

Or, for short:

 label.textAlignment = .Center; 

Swift 3

 label.textAlignment = .center 
+109
Jun 04
source share
β€” -

Enumerations in Swift are different from each other than in Objective-C.

What in Objective-C will be NSTextAlignmentCenter in Swift NSTextAlignment.Center .

+2
Jun 04 '14 at 10:02
source share

To use the center, myLabel.textAlignment = NSTextAlignment.Center

0
Feb 21 '15 at 5:34
source share



All Articles