ios - '_? ?' is not convertible to ' ()' 与 NSMutableAttributedString

标签 ios string swift uilabel

我不得不说我是 Swift 的新手,我一直坚持在 UILabel 中设置 NSMutableAttributedString

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

最后一行给我:'_ ??'不能转换为“()”,所以我什至无法编译。

我也试过:

tweetTextLabel?.text = attributedString.string

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

最佳答案

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

tweetTextLabel?.attributedText = attributedString

关于ios - '_? ?' is not convertible to ' ()' 与 NSMutableAttributedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31288494/

相关文章:

iphone - 我可以在特定时刻阻止网络访问吗?

iOS JSON NSString 解析

string - 在 bash 中返回破折号之前的子字符串,后跟数字

C- 检查字符串中的字符是否属于数组

ios - 尽管框架相同,但 UIBlurEffectView 小于自动布局的parentView

iphone - iOS:我的第一个应用程序的初学者帮助:切换 View ?

ios - 从选择器变量中查找参数类/类型 - Objective-C

ios - 将保存的上下文从 AppDelegate 加载到另一个 ViewController

java - java.lang.String 中存在的 contains() 方法在某些情况下无法正常运行,有人可以解释一下这种行为吗

objective-c - 当 NSStatusBar IconView 图像更改时,我的弹出 View Controller 消失