I was wondering if there is a way to check if a text field contains a certain character and if that is the case, change the keyboard type displayed. This is what I have tried but it does not manage to change. This is action occurs when editing the text field is changed.
@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
}
}
Just call reloadInputViews() on your UITextField after you change keyboard's type
textField.keyboardType = .numberPad
textField.reloadInputViews()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With