1

このコードは 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];

ただし、NSForgroundColorAttributeName は iOS 5 では定義されていないため、iOS 5 で動作する以前のコードと同等のコードが必要です。

4

1 に答える 1

0

同等の方法は、色の CGColorRef で kCTForegroundColorAttributeName を使用することです。

私の CoreText の紹介をここで参照してください: http://www.cocoanetics.com/2011/01/befriending-core-text/

于 2012-12-21T19:13:22.560 に答える