'_??'不能使用 NSMutableAttributedString 转换为 '()'
'_ ??' is not convertible to '()' with NSMutableAttributedString
我不得不说我是 Swift 的新手,我一直坚持在 UILabel
中设置 NSMutableAttributedString
。
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
但是这样我失去了颜色属性
您应该设置为 UILabel
的 attributedText
属性,例如:
tweetTextLabel?.attributedText = attributedString
我不得不说我是 Swift 的新手,我一直坚持在 UILabel
中设置 NSMutableAttributedString
。
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
但是这样我失去了颜色属性
您应该设置为 UILabel
的 attributedText
属性,例如:
tweetTextLabel?.attributedText = attributedString