disable autocorrectionType is not working with UITextfield

Viewed 1160

I have created RegisterViewController with email, password and confirm password fields.

In email field, it always show suggest email on QuickType's keyboard bar but other fields not show anything.

How it know which field is email or not ? I swear I didn't set anything to textfield. I already set autocorrectionType = .no on my base class text field but it still show suggest on bar.

Can anyone help me about this ?

keyboard screenshot showing suggestion bar

4 Answers

Here's what you can try -

textField.autocapitalizationType = .none
textField.autocorrectionType = .no
textField.spellCheckingType = .no

try textField.textContentType = .none

You can try this:

textField.disableAutocorrection(true)
textField.disableAutocorrection(false)

Or this:

textField.autocorrectionType = .yes
textField.autocorrectionType = .no

To hide the bar (predictive bar), use this code:

if #available(iOS 9.0, *) {
    var item = textFeild.inputAssistantItem
    item.leadingBarButtonGroups = [];
    item.trailingBarButtonGroups = [];
}

This also may help in your case:

self.passwordField.isSecureTextEntry = true
    
if #available(iOS 11.0, *) {
    self.emailField.textContentType = .username
    self.emailField.keyboardType = .default
}
    
if #available(iOS 12.0, *) {
    self.passwordField.textContentType = .password
    self.passwordField.keyboardType = .default
}

this is not autocorrection. this is suggestion

Use below code to disable suggestion

if #available(iOS 12, *) {
    // iOS 12 & 13: Not the best solution, but it works.
    passwordTextField.textContentType = .oneTimeCode
} else {
    // iOS 11: Disables the autofill accessory view.
    // For more information see the explanation below.
    emailTextField.textContentType = .init(rawValue: "")
    passwordTextField.textContentType = .init(rawValue: "")
}
Related