【问题标题】:Change keyboard type of a text field in Swift during runtime在运行时更改 Swift 中文本字段的键盘类型
【发布时间】:2019-03-05 18:59:14
【问题描述】:

我想知道是否有办法检查文本字段是否包含某个字符,如果是这样,请更改显示的键盘类型。这是我尝试过的,但它无法改变。这是在编辑文本字段更改时发生的操作。

    @IBAction func decOrNot(_ sender: Any) {
    let cont = "1"
    let field = testKaede.text
    if (field!.contains(cont)) {
        self.testKaede.keyboardType = UIKeyboardType.numberPad
    }
    else {
        self.testKaede.keyboardType = UIKeyboardType.decimalPad
    }
}

【问题讨论】:

    标签: swift keyboard textfield


    【解决方案1】:

    更改键盘类型后,只需在 UITextField 上调用 reloadInputViews()


    textField.keyboardType = .numberPad
    textField.reloadInputViews()
    

    【讨论】:

      猜你喜欢
      • 2011-04-16
      • 1970-01-01
      • 2017-10-02
      • 2020-07-14
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      相关资源
      最近更新 更多