Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autocorrect issue with a colored UITextview

I'm using in my app a textview with blue colored background.

When autocorrect is enabled, whenever it corrects a word a white box forms around the word and the text's color changes also.

Any ideas on how to stop this effect?

like image 712
Basillius2 Avatar asked Dec 03 '12 13:12

Basillius2


1 Answers

Nope, I think you can't change the color of the overlay or the textcolor out of the box..

This is a hard one, if you put a breakpoint in - (void) layoutSubviews {..} of your view you'll see UIKit has drawn a 'UITextSelectionView' above the text...

I tried to subclass UITextView to see if its layoutSubviews get's fired and it seems it does!

So I tried to remove the overlay:

- (void) layoutSubviews {
    [super layoutSubviews];

    for (UIView *subview in self.subviews) {
        if ([NSStringFromClass([subview class]) isEqualToString:@"UITextSelectionView"]) {
            DLog(@"Subview %@", [subview debugDescription]);
            [subview removeFromSuperview];
            break;
        }
    }
}

And it worked.. but that results in missing the cursor, and disabling any selection :(

I think you'll have to disable autocorrect..

I'll re-start the bounty if someone finds a real answer!

like image 166
Tieme Avatar answered Oct 17 '22 00:10

Tieme