iOS 8 - 如何隐藏键盘上方的建议列表?

Kha*_*war 50 ios swift xcode6 ios8

有没有办法隐藏键盘上方的建议列表?我在文档中找不到任何解决方案.

Mic*_*lum 97

就在这里.您必须在文本字段/ text /任何其他符合UITextInputTraits协议的类上禁用自动更正,这可以通过autocorrectionType属性来完成.

textField.autocorrectionType = .no
Run Code Online (Sandbox Code Playgroud)

此外,如果您感兴趣,以下是唯一 默认情况下没有建议的UIKeyboardType.

  • DecimalPad
  • 数字小
  • PhonePad

  • @NJGadhiya这是非常相似的.唯一的区别是枚举中的点分隔和分号`textField.autocorrectionType = UITextAutocorrectionTypeNo;`. (4认同)
  • UITextAutocorrectionType.No,禁用建议但不隐藏iOS9.2中的栏.是否有单独的代码隐藏了建议栏? (3认同)

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)

这对我有用!

  • 如果我设置此 AND .auto CorrectionType = no,我只能将预测文本栏隐藏在键盘上。 (3认同)

Kir*_*air 6

在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)


aus*_*s99 5

(2020 年 6 月编辑:Xcode 11.3.1 仍然如此)


在较新版本的 Xcode 故事板中,您还可以在故事板中设置键盘特征(右侧面板,属性检查器,然后查找文本输入特征并选择您想要的特征,至少在 Xcode 9 中)。特别是,为 Correction trait 选择“No”,如下例所示。有趣的是,这是针对内容类型用户名的,例如,与密码等内容类型不同,更正特征的默认选择是打开更正。 在故事板中设置它的示例