I have UITextViewone that is parsed, and its attributes change when certain characters are entered. The text does not change, only the attributes that describe the formatting of the text.
If I parse every character record, I essentially capture textby creating an attribute string with the correct formatting and setting the attributedTexttextview property to my new attributed string. This completely violates the auto-correct, double-space shortcut and spell check.
If I analyze only when entering certain special characters, this works a little better, but I get strange errors, since the second word of each sentence is capitalized.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (text.length == 0) {
return YES;
}
unichar firstCharacterInText = [text characterAtIndex:0];
if () {
[self processTextView];
}
}
- (void) processTextView {
NSString *text = self.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
[attributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontRegular size:12.0f] range:NSMakeRange(0, text.length)];
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor textColor] range:NSMakeRange(0, text.length)];
}
: textview attributedText UITextView?