Disable auto correction of UITextField

Viewed 37098

When I try to edit texts in my iPhone application (UITextfield), it auto-corrects my input.

Could you let me know how can I disable this?

8 Answers
UITextField* f = [[UITextField alloc] init];
f.autocorrectionType = UITextAutocorrectionTypeNo;        

You can use the UITextInputTraits protocol to achieve this:

myInput.autoCorrectionType = UITextAutocorrectionTypeNo;

See here for more details.

In SwiftUI, you can use the .disableAutocorrection(true) modifier.

Hiere is a real life example:

VStack {
    TextField("title", text: $LoginModel.email)
        .autocapitalization(.none)
        .disableAutocorrection(true)
        .foregroundColor(.white)
}

Swift 5:

This is how I am achieving for email address field in my project

private let emailTextField: UITextField = {
    let tf = CustomTextField(placeholder: "Email address")
    tf.keyboardType = .emailAddress
    tf.autocorrectionType = .no        //disable auto correction
    tf.autocapitalizationType = .none   //disable default capitalization
    return tf
}()

CustomTextField is my extension class (not important here)

Related