65

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

Khawar
  • 9,151
  • 9
  • 46
  • 67

5 Answers5

126

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
iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
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
}
Igor
  • 12,165
  • 4
  • 57
  • 73
Kiran P Nair
  • 2,041
  • 22
  • 31
10

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!

Jonathan Hoche
  • 449
  • 6
  • 6
10

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

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

The other approaches did not work

Sam Doggett
  • 248
  • 5
  • 8
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

shim
  • 9,289
  • 12
  • 69
  • 108
auspicious99
  • 3,902
  • 1
  • 44
  • 58