Core Text setting default color and color of specific words

colors, core-text, ios

Solution

While trying to better explain the problem I was having, I found the error... I was doing this

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

rather than this

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

It helps to make sure you're using the right sort of color object!

Problem

I'm pretty new to using Core Text, and I'm not finding much information on how to use the color attributes... how would one set the default text color, then change colors for specific ranges? What I'm trying to do is to draw a short sentence. I'd like the default color of the text to be a light gray, and then to mark a single word in red to highlight it.

Original source