4

我正在尝试设置WKInterfaceLabel使用setAttributedText功能的对齐方式。这是我的代码:

 var paragraphStyle = NSParagraphStyle.defaultParagraphStyle()
 paragraphStyle.alignment = NSTextAlignment.Center
 var attributedDictonary = [NSForegroundColorAttributeName:UIColor.greenColor(), NSParagraphStyleAttributeName:paragraphStyle]
 var attributeString = NSAttributedString(string: "TextAttributed", attributes: attributedDictonary)
 self.titleLabel.setAttributedText(attributeString)

但我遇到了这条线的问题:

paragraphStyle.alignment = NSTextAlignment.Center

我收到错误:Cannot assign to 'alignment' in 'paragraphStyle'

如何设置对齐WKInterfaceLabel使用setAttributedText

4

1 回答 1

5

您需要使用NSMutableParagraphStyle

var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.CenterTextAlignment
于 2015-04-20T08:43:53.420 回答