不同的颜色在UITextView [英] Different colors in UITextView
问题描述
我尝试在我的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 UIKit添加参考: I try to add string with different colors in my UITextView. I wrote this code Maybe it is incorrect attribute, can you tell me what attribute change color for text? Try using NSAttributedString UIKit Additions Reference: Character Attributes 这篇关于不同的颜色在UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!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
instead of kCTForegroundColorAttributeName
.