Disable autocorrect UITextView

2019-03-01 16:57发布

问题:

Does anyone know how to disable autocorrect programming in uitextview? I have the following code, but it doesn't work.

- (void)_setUpTextView {
    self.textView = [[UITextView alloc] initWithFrame:self.bounds];
    self.textView.accessibilityLabel = @"CommentTextView";
    self.textView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.textView setFont:[[AppearanceManager sharedManager] brightenFontWithSize:26.0f]];
    [self.textView.layer setCornerRadius:5.0f];
    self.textView.delegate = self;
    self.textView.autocorrectionType = FALSE; // or use  UITextAutocorrectionTypeNo
    self.textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self addSubview:self.textView];
}

回答1:

Whoa there buddy, you commented out your own answer. Make this change:

self.textView.autocorrectionType = UITextAutocorrectionTypeNo;

And you should be good to go. autoCorrectionType does not take a boolean as an argument.