How to tell a UITextField to use the NumberPad Keyboard in code?
I created a UITextField 开发者_开发知识库in code, now I have now idea how to define the keybaord that should appear ? I just get the standard keybboard, but I need a numberpad ?!
Thanks
You need to set the keyboardType
property to UIKeyboardTypeNumberPad
.
Obj-C:
textField.keyboardType = UIKeyboardTypeNumberPad;
And simply use .numberPad
in Swift.
Swift:
textField.keyboardType = .numberPad
You can also easily do this in the XIB file
You can specify the Keyboardtype like this:
.keyboardType(UIKeyboardType.numberPad)
here with some context:
@State var text : String = ""
TextField("text", text: self.$text).keyboardType(UIKeyboardType.numberPad)
精彩评论