问题
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