The color of the main text and the color of specific words

I am new to using Core Text, and I do not find much information on how to use color attributes ... how would I set the text color to default and then change colors for certain ranges?

I am trying to make a short sentence. I would like the default text color to be light gray and then highlight one red word to highlight it.

+3
source share
2 answers

When I tried to better explain my problem, I found an error ... I did it

UIColor _textColor = [UIColor grayColor];
[string addAttribute:(id)kCTForegroundColorAttributeName value:(id)_textColor range:NSMakeRange(0, [string length])];

but not

UIColor _textColor = [UIColor grayColor];   
[string addAttribute:(id)kCTForegroundColorAttributeName value:(id)_textColor.CGColor range:NSMakeRange(0, [string length])];

This helps make sure that you are using the correct color object!

+7
source

There are two ways to solve this problem.

1) UILable UITextView, (CATextLayer) / , NSAttributedString

2) NSAttributedString. OHAttributedLabel, UILabel NSAttributedString .

, .

, , cehck : UITextView?

+1

All Articles