开发者

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

How to tell a UITextField to use the NumberPad Keyboard in code?


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜