我正在尝试使用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
的对齐方式? 最佳答案
您需要使用NSMutableParagraphStyle
:
var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.CenterTextAlignment