Different colors in UITextView

夙愿已清 提交于 2019-12-24 08:13:45

问题


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?


回答1:


Try using NSForegroundColorAttributeName instead of kCTForegroundColorAttributeName.

NSAttributedString attribute keys



来源:https://stackoverflow.com/questions/14823280/different-colors-in-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!