不同的颜色在UITextView [英] Different colors in UITextView

查看:121
本文介绍了不同的颜色在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

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;

Maybe it is incorrect attribute, can you tell me what attribute change color for text?

Try using NSForegroundColorAttributeName instead of kCTForegroundColorAttributeName.

NSAttributedString UIKit Additions Reference: Character Attributes

这篇关于不同的颜色在UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆