With the release of iOS 8 I would like to disable the predictive text section of the keyboard when I begin typing in a UITextField. Not sure how this is done, any help would be appreciated!
Disable UITextField Predictive Text
Asked Answered
This question is semi-out-of-date; at the time it existed, "Predictive Text" was an ambiguous phrase which often was used loosely to mean auto-correct, but these days that phrase generally refers to the native Predictive Text toolbar that appears above the keyboard. The 8-year-old selected-answer deals with the ambiguous meaning, for those of us in the future, wanting to disable the native predictive text bar the following answer is what you are looking for: https://mcmap.net/q/224006/-disable-uitextfield-predictive-text — OP I encourage you to update your selected answer as well. –
Gaw
Setting the autoCorrectionType to UITextAutocorrectionTypeNo did the trick
Objective-C
textField.autocorrectionType = UITextAutocorrectionTypeYes;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
Swift 2
textField.autocorrectionType = .Yes
textField.autocorrectionType = .No
Swift 3
textField.autocorrectionType = .yes
textField.autocorrectionType = .no
SwiftUI
textField.disableAutocorrection(true)
textField.disableAutocorrection(false)
Careful:
myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
has to be placed before [myTextField becoreFirstResponder];
to be effective. –
Carlycarlye Does this not disable Auto Correct? The problem here is "Predictive Keyboard Toolbar" being added, but doesn't setting autoCorrection to UITextAutocorrectionTypeNo turn off Auto Correct as well? –
Tashia
My question is the other way: can you disable the autocorrection but keep the word suggestions bar? These are two independent functionalities but seem to be controlled by the same setting, really stupid... –
Brevier
Damn! i had the same issue as @Janneman, and i was convinced the functionality of "quick type bar" could be combined with "disabling auto correction", since i was seeing this exact behavior on twitter, ig, etc, but no matter what i coded, it would not work on simulator... until i realized that this is a CUSTOMIZATION IN THE USER KEYBOARD SETTINGS (General > Keyboard > Auto-Correction). Just leave it as
textField.autocorrectionType = .default
, and whether text gets auto corrected will be up to the user, not you, as it should be –
Geriatrician this much high voted ans, but didn't worked. –
Corvese
Swift 2
textField.autocorrectionType = .Yes
textField.autocorrectionType = .No
Swift 3
textField.autocorrectionType = .yes
textField.autocorrectionType = .no
The chosen answer is correct, but you also have an option to do the same in storyboard.
All you need is to select your textfield, and under "show the Attributes inspector", set Correction to NO.
For me it worked also setting the spellCheckingType as no (iOS 15, Swift 5+)
textField.autocorrectionType = .no
textField.spellCheckingType = .no
This should be the accepted answer, the others only disable siri auto-correct, they don't disable the predictive text bar like
spellCheckingType
does. Thanks! –
Gaw like this you on or off UITextAutocorrectionType
myTextView.autocorrectionType = UITextAutocorrectionTypeNo;
myTextView.autocorrectionType = UITextAutocorrectionTypeYes;
Is there any way to do this but keep the auto correct functionality? –
Photogenic
Setting autocorrectionType to .no allowed my tableview to scroll to the last entry. With predictive text on the last line was blocked from being selected.
FIXED for SWIFT-3:
myTextField.autocorrectionType = .no
if you are using storyboard select your Text Field and under the attributes inspector -
Correction = No
Smart Insert = No
[_textfield setTextContentType:0];
The
textContentType
property of UITextField
is of type UITextContentType
which is an alias for NSString
. Assigning a value of 0
is the same as assigning nil
(textfield.textContentType = nil
). As the documentation for textContentType
states, nil
is the default value. So setting it to nil
would not change the default behavior. –
Citreous There are eight existing answers to this question, including a top-voted, accepted answer with nearly two hundred votes. Are you certain your solution hasn't already been given? If not, why do you believe your approach improves upon the existing proposals, which have been validated by the community? Offering an explanation is always useful on Stack Overflow, but it's especially important where the question has been resolved to the satisfaction of both the OP and the community. Help readers out by explaining what your answer does different and when it might be preferred. –
Quicksand
© 2022 - 2024 — McMap. All rights reserved.