Question

This code works well on iOS 6

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:textView.text];

[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[textView.text rangeOfString:self.searchString options:NSCaseInsensitiveSearch range:searchRange]];

[textView setAttributedText:attributedString];

However NSForegroundColorAttributeName is undefined in iOS 5, so I want the equivalent of the previous code that works in iOS 5.

Was it helpful?

Solution

The equivalent is to use the kCTForegroundColorAttributeName with a CGColorRef for the color.

See my CoreText introduction here: http://www.cocoanetics.com/2011/01/befriending-core-text/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top