【问题标题】:How to set alignment for WKInterface Label using setAttributedText如何使用 setAttributedText 为 WKInterface 标签设置对齐方式
【发布时间】:2015-04-20 08:35:19
【问题描述】:

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

 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'

如何使用setAttributedTextWKInterfaceLabel 设置对齐方式?

【问题讨论】:

    标签: swift setattribute xcode-6.2 nsparagraphstyle wkinterfacelabel


    【解决方案1】:

    你需要使用NSMutableParagraphStyle:

    var paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.alignment = NSTextAlignment.CenterTextAlignment
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多