Background
So, with iOS 6, UITextView can take the String attribute, which can be useful for syntax highlighting.
I make several regex patterns in -textView:shouldChangeTextInRange:replacementText: and often I need to change the color of an already entered word. I see no other options than resetting the Text attribute, which takes time.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
This works fine on the simulator, but on iPad 3, each -setAttributedText takes several hundred milliseconds.
I filed an Apple error requesting to mutate the Text attribute. It has been marked as a duplicate, so I cannot understand what they are saying about it.
Question
A more specific question: How to change the color of certain ranges in a UITextView with large multi-colored text with enough performance to do this in each shouldReplaceText... ?
The broader question is: How do I make syntax highlighting using UITextView in iOS 6?
source share