iOS 8 - How to hide suggestion list above keyboard

2020-02-17 06:08发布

问题:

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

回答1:

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


回答2:

In swift 2 hide Suggestion using this code :

textField.autocorrectionType = UITextAutocorrectionType.No

Swift 3:0

textfield.autocorrectionType = .no

To hide bar (Predictive bar) use this code :

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

For Disable copy past , use this function

override func selectionRectsForRange(range: UITextRange) -> [AnyObject] {
    return []
}

override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
    let menu = UIMenuController.sharedMenuController()
    menu.menuVisible = false
    return false
}

Swift 3

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


}


回答3:

(Edit in Oct 2019: still true for Xcode 11.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.



回答4:

For anybody who landed here that is attempting to disable/hide the iOS 11 password autofill bar, here is one solution.