iOS 8 - How to hide suggestion list above keyboard?
Is there any way to hide suggestions list above keyboard? I couldn't find any solution in documentation.
Solution 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
Solution 2:
Swift 4.0 +:
textfield.autocorrectionType = .no
To hide the bar (predictive bar), use this code:
if #available(iOS 9.0, *) {
var item = textFeild.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
}