我尝试以下操作,但没有成功。当用户点击一个UiTextfield时,我需要自动将键盘视图更改为数字视图,这可能吗?
我尝试以下操作,但没有成功。当用户点击一个UiTextfield时,我需要自动将键盘视图更改为数字视图,这可能吗?
UITextInputTraits
协议(UITextField
符合该协议)具有 keyboardType
类型为 UIKeyboardType
的属性。
myTextField.keyboardType = UIKeyboardTypeNumberPad;
UITextField符合UITextInputTraits协议,这意味着它具有keyboardType属性,您可以进行设置。
myField.keyboardType = UIKeyboardTypeNumberPad;
您也可以通过界面构建器进行设置。从文本输入特征中将键盘设置为数字键盘即可。
currentTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
在编写代码时,最好先写父类 UIKeyboardType
,然后再继续使用键盘枚举 numberPad
。这是一种良好的实践。
myTextField.keyboardType = UIKeyboardType.numberPad
myTextField.keyboardType = .numberPad
的意思是将myTextField
文本框的键盘类型设置为数字键盘。 - Andy