Enums 敏捷的UILabel文本对齐

Enums 敏捷的UILabel文本对齐,enums,uilabel,swift,Enums,Uilabel,Swift,我用swift创建我的UILabel: let label = UILabel(frame: CGRect( x: 50, y: 50, width: 100, height: 50)) 设置属性似乎很容易: label.textColor = UIColor.redColor() 如何实现诸如textAlignment之类的枚举类型? 在目标C中是 label.textAlignment = NSTextAlignmentCenter; 但在swift中,它似乎不起作用。这些现在是enu

我用swift创建我的UILabel:

let label = UILabel(frame: CGRect( x: 50, y: 50, width: 100, height: 50))
设置属性似乎很容易:

label.textColor = UIColor.redColor()
如何实现诸如textAlignment之类的枚举类型? 在目标C中是

label.textAlignment = NSTextAlignmentCenter;

但在swift中,它似乎不起作用。

这些现在是
enum
s

你可以做:

label.textAlignment = NSTextAlignment.center;
或者,简而言之:

label.textAlignment = .center;
Swift 3

label.textAlignment = .center

Swift中的枚举与Objective-C中的枚举不同


Objective-C中的
NSTEXTALIGNENTCENTER
在Swift
NSTEXTALIGNENT.Center

对于中心使用,
myLabel.textAlignment=NSTextAlignment.Center

明白了!我的错误是我在写。你能链接到文档吗?正如我所看到的,他们必须从ObjC重写这些枚举。这个答案很有帮助。我试过了,中间看起来不对劲。检查了枚举并使用了.Justified,它看起来更好枚举{NSTextAlignmentLeft=0,NSTextAlignmentCenter=1,NSTextAlignmentRight=2,NSTextAlignmentJustified=3,NSTextAlignmentNatural=4,};