我正在尝试设置对齐方式WKInterfaceLabel
using 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
using setAttributedText
?
你需要使用NSMutableParagraphStyle
:
var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.CenterTextAlignment
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)