Highlight
以下の関数を呼び出すメニュー項目があります。この関数は、選択したテキストの色を変更し、正常に機能します。ただし、それを正しく行っているかどうかはわかりません。_myTextView
(an UITextView
) に大量のテキストがある場合、パフォーマンスの問題が発生する可能性があることが心配です。
それを見て、より良い方法があれば提案していただけますか?
- (void)highlight {
NSRange selectedRange = _myTextView.selectedRange;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
initWithAttributedString:_myTextView.attributedText];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:selectedRange];
_myTextView.attributedText = attributedString;
}