我想知道是否有一种方法可以检查文本字段是否包含特定字符,如果是这样,请更改显示的键盘类型。这是我尝试过的,但无法改变。这是在编辑文本字段发生更改时发生的操作。
@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
}
}
最佳答案
更改键盘类型后,只需在 UITextField
上调用 reloadInputViews()
textField.keyboardType = .numberPad
textField.reloadInputViews()
关于swift - 在运行时更改 Swift 中文本字段的键盘类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55009749/