在 iOS 中,有没有一种方法可以防止 UITextView 中的自动拼写更正?

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

我已经实现了 textView:shouldChangeTextInRange:replacementText: 如下所示。我需要它来删除提示文本并结束编辑。我需要添加其他东西来关闭自动更正吗?或者我还能如何关闭它?

- (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;
}

你可以在故事板上设置它。 Select UITextView 检查一下:

如果您不使用故事板,可以使用此代码:

yourTextView.autocorrectionType = UITextAutocorrectionTypeNo;