【问题标题】:'_ ??' is not convertible to '()' with NSMutableAttributedString'_ ??不能使用 NSMutableAttributedString 转换为 '()'
【发布时间】:2015-07-08 09:22:16
【问题描述】:

我不得不说我对 Swift 还很陌生,我一直在设置 NSMutableAttributedString 中的 UILabel

var attributedString = NSMutableAttributedString("random string for this example")
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(1, 3))
tweetTextLabel?.text = attributedString

最后一行给了我:'_ ??' is not convertible to '()',所以我什至无法编译。

我也试过:

tweetTextLabel?.text = attributedString.string

但是这样我就失去了颜色属性

【问题讨论】:

  • tweetTextLabel?.attributedText = attributedString
  • 非常感谢,我没有注意到UILabel中的那个方法

标签: ios string swift uilabel


【解决方案1】:

您应该设置为UILabelattributedText 属性,例如:

tweetTextLabel?.attributedText = attributedString

【讨论】:

    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 2023-03-22
    • 2013-12-27
    • 1970-01-01
    相关资源
    最近更新 更多