Mic*_*lum 97
就在这里.您必须在文本字段/ text /任何其他符合UITextInputTraits协议的类上禁用自动更正,这可以通过autocorrectionType属性来完成.
textField.autocorrectionType = .no
Run Code Online (Sandbox Code Playgroud)
此外,如果您感兴趣,以下是唯一 默认情况下没有建议的UIKeyboardType.
Sam*_*ett 14
截至 2022 年 8 月 19 日,以下内容对我有用:
textField.spellCheckingType = .no
textField.autocorrectionType = .no
Run Code Online (Sandbox Code Playgroud)
其他方法均无效
小智 10
iOS 15(可能更早)
上面的答案不起作用:要删除建议列表(预测 - 拼写检查)需要进行:
textField.spellCheckingType = .no
Run Code Online (Sandbox Code Playgroud)
这对我有用!
在swift 2中使用此代码隐藏建议:
textField.autocorrectionType = UITextAutocorrectionType.No
Run Code Online (Sandbox Code Playgroud)
斯威夫特3:0
textfield.autocorrectionType = .no
Run Code Online (Sandbox Code Playgroud)
要隐藏栏(Predictive bar),请使用以下代码:
if #available(iOS 9.0, *) {
var item = textFeild.inputAssistantItem
item.leadingBarButtonGroups = [];
item.trailingBarButtonGroups = [];
}
Run Code Online (Sandbox Code Playgroud)
对于禁用复制过去,请使用此功能
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
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特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
}
Run Code Online (Sandbox Code Playgroud)