65

Is there any way to hide suggestions list above keyboard? I couldn't find any solution in documentation.

1
  • 2
    Only the user can hide it. The only you as a developer can do is using a keyboard type that not support autocorrect. Jun 10, 2014 at 11:46

5 Answers 5

127

Yes there is. You have to disable autocorrection on the text field/text/any other class that conforms to the UITextInputTraits protocol, which can be done through the autocorrectionType property.

textField.autocorrectionType = .no

Additionally, if you're interested, the following are the only UIKeyboardTypes that don't have suggestions by default.

  • DecimalPad
  • NumberPad
  • PhonePad
7
  • Any idea for Objective-C? Nov 18, 2014 at 7:48
  • 4
    @NJGadhiya It's very similar. The only difference is the dot separation in the enum and a semicolon textField.autocorrectionType = UITextAutocorrectionTypeNo;. Nov 21, 2014 at 18:48
  • 4
    UITextAutocorrectionType.No, which disable the suggestions but it doesn't hide the bar in iOS9.2. Is there a separate code that hides the suggestion bar?
    – selva
    Jan 28, 2016 at 22:05
  • This isn't working for me on a UISearchbar NumberPad keyboard (it still shows telephone suggestions above). Testing in iPhone 6S real device via Swift 4 and Xcode 9,2. Anyone else? Jan 30, 2018 at 11:43
  • 1
    This doesn't work on iphone 8plus real device swift 4 xcode 9.4 Aug 9, 2018 at 16:01
16

As of August 19th, 2022 the following worked for me:

textField.spellCheckingType = .no
textField.autocorrectionType = .no

The other approaches did not work

15

Swift 4.0 +:

textfield.autocorrectionType = .no

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

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

For disabling copy-and-paste, use this function:

override func selectionRects(for range: UITextRange) -> [Any] {
    return []
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    let menu = UIMenuController.shared
    menu.isMenuVisible = false
    return false
}
11

iOS 15 (maybe ealier)

The answers above did not work: To remove the Suggestion list (predictive - spell checking) Need to make:

textField.spellCheckingType = .no

That's what worked for me!

3
  • 3
    I was only able to get the predictive text bar to hide on the keyboard if I set this AND .autocorrectionType = no.
    – FateNuller
    Jul 26, 2022 at 19:10
  • iOS 16, yes you need both lines to remove the suggestion bar. Works for searchBars as well: searchBar.autocorrectionType = .no searchBar.spellCheckingType = .no Feb 12, 2023 at 9:10
  • both things are needed Mar 7, 2023 at 17:53
6

(Edited in June 2020: still true for Xcode 11.3.1)


In more recent versions of Xcode storyboards, you can also set the keyboard traits in the storyboard (right panel, the attributes inspector, then look for Text Input Traits and select the traits you want, at least in Xcode 9). In particular, select "No" for the Correction trait, as shown in the example below. Interestingly, this is for content type Username, and the Default selection for the Correction trait was to turn on Correction, unlike a content type like Password, for example.

Example of setting this in the storyboard

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.