-->

不同颜色的UITextView(Different colors in UITextView)

2019-10-17 17:22发布

我试着用不同的颜色在我的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;

也许是不正确的属性,你能告诉我什么属性改变颜色的文字?

Answer 1:

尝试使用NSForegroundColorAttributeName代替kCTForegroundColorAttributeName

NSAttributedString属性键



文章来源: Different colors in UITextView