Xcode中的数字键盘

tha*_*ary 10 iphone keyboard xcode textfield

有没有人知道如何在iPhone中显示数字键盘而不是默认键盘?有没有办法只为数字过滤文本字段?我需要从代码而不是来自界面构建器那样做

谢谢

Joh*_*ang 29

或者,在代码中设置textfield的keyboardType属性:

textField.keyboardType = UIKeyboardTypeNumberPad
Run Code Online (Sandbox Code Playgroud)

可用选项包括:

UIKeyboardType为给定的基于文本的视图显示的键盘类型.

typedef enum {
UIKeyboardTypeDefault,
UIKeyboardTypeASCIICapable,
UIKeyboardTypeNumbersAndPunctuation,
UIKeyboardTypeURL,
UIKeyboardTypeNumberPad,
UIKeyboardTypePhonePad,
UIKeyboardTypeNamePhonePad,
UIKeyboardTypeEmailAddress,
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable} UIKeyboardType;

但值得注意的是,NumberPad没有小数点可供输入.如果你需要,你将不得不使用其他东西.

  • UIKeyboardTypeNumbersAndPunctuation对我来说听起来不错. (3认同)

小智 9

现在有一个包含小数的键盘,您可以使用以下代码.

textField.keyboardType = UIKeyboardTypeDecimalPad;