Disable UITextField Predictive Text
Asked Answered
D

9

93

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!

Distressful answered 10/9, 2014 at 14:5 Comment(1)
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
D
194

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)
Distressful answered 10/9, 2014 at 14:36 Comment(5)
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 beGeriatrician
this much high voted ans, but didn't worked.Corvese
A
19

Swift 2

textField.autocorrectionType = .Yes
textField.autocorrectionType = .No

Swift 3

textField.autocorrectionType = .yes
textField.autocorrectionType = .no
Aleron answered 3/4, 2015 at 19:51 Comment(0)
D
17

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.

See attached image

Dentelle answered 28/10, 2017 at 0:5 Comment(0)
D
12

For me it worked also setting the spellCheckingType as no (iOS 15, Swift 5+)

        textField.autocorrectionType = .no
        textField.spellCheckingType = .no
Dannadannel answered 25/4, 2022 at 11:59 Comment(1)
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
B
7

like this you on or off UITextAutocorrectionType

myTextView.autocorrectionType = UITextAutocorrectionTypeNo;  
myTextView.autocorrectionType = UITextAutocorrectionTypeYes;
Bitartrate answered 10/10, 2014 at 8:53 Comment(1)
Is there any way to do this but keep the auto correct functionality?Photogenic
T
2

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.

Tithable answered 21/8, 2018 at 22:51 Comment(0)
B
1

FIXED for SWIFT-3:

myTextField.autocorrectionType = .no
Bobinette answered 1/12, 2016 at 13:35 Comment(0)
P
0

enter image description here

if you are using storyboard select your Text Field and under the attributes inspector -

Correction = No
Smart Insert = No 
Phrensy answered 22/5, 2022 at 13:26 Comment(0)
R
-1
[_textfield setTextContentType:0];
Recover answered 15/4 at 23:19 Comment(2)
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.