Neznajka
Neznajka

Reputation: 305

Different colors in UITextView

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?

Upvotes: 1

Views: 1572

Answers (1)

rob mayoff
rob mayoff

Reputation: 385540

Try using NSForegroundColorAttributeName instead of kCTForegroundColorAttributeName.

NSAttributedString attribute keys

Upvotes: 3

Related Questions