Search code examples
iosuitextviewautocorrect

In iOS is there a way to prevent auto spelling correction in a UITextView?


I already implement textView:shouldChangeTextInRange:replacementText: as shown below. I need it to remove the prompt text and also to end editing. Do I need to add something else to it to turn off auto-correction? Or how else do I turn it off?

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    if ([self.noteView.text isEqualToString:initialText]) {
        textView.text = @"";
        self.noteView.textColor = [UIColor blackColor]; // initialText was lightGray
    } else if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
    }
    return YES;
}

Solution

  • You can set it on storyboard. Select UITextView and check it:Image

    If you don't user storyboard, you can use this code:

    yourTextView.autocorrectionType = UITextAutocorrectionTypeNo;