我尝试在UITextView中添加具有不同颜色的字符串。我写了这段代码
NSMutableAttributedString* attString =
[[NSMutableAttributedString alloc]initWithString:view.text]; //view is my UITextView
[attString addAttribute:(NSString*)kCTForegroundColorAttributeName
value:[UIColor greenColor]
range:(NSRange){attString.length-8, 8}];
view.attributedText = attString;
可能是属性不正确,您能告诉我什么属性会更改文本的颜色吗?
最佳答案
尝试使用NSForegroundColorAttributeName
而不是kCTForegroundColorAttributeName
。
NSAttributedString attribute keys
关于ios - UITextView中的不同颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14823280/