ios 如何在 iPhone 上默认显示数字键盘?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3796772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I show the numeric keyboard by default on iPhone?
提问by Pablo
I'm trying the following with no luck. When the user click on a UiTextfield I need to change the keyboard view to the numeric view automatically, is this possible?
我正在尝试以下但没有运气。当用户单击 UiTextfield 时,我需要将键盘视图自动更改为数字视图,这可能吗?
回答by Jacob Relkin
The UITextInputTraits
protocol (which UITextField
conforms to) has a keyboardType
property of type UIKeyboardType
.
的UITextInputTraits
协议(其UITextField
符合)具有keyboardType
类型的属性UIKeyboardType
。
myTextField.keyboardType = UIKeyboardTypeNumberPad;
回答by taskinoor
UITextField conforms to UITextInputTraits protocol which means it has keyboardType property which you can set.
UITextField 符合 UITextInputTraits 协议,这意味着它具有可以设置的 keyboardType 属性。
myField.keyboardType = UIKeyboardTypeNumberPad;
You can also set it via interface builder. From the text input traits set the keyboard to number pad and that's all.
您也可以通过界面构建器进行设置。从文本输入特性中,将键盘设置为数字键盘,仅此而已。
回答by kalpa
回答by Not Your Average Coder
If you want to show a numerical keyboard but also need to be able to use decimal points, currency symbols, or other characters, you can have the keyboard default to the back side of the alphabet keyboard.
如果您想显示数字键盘但还需要能够使用小数点、货币符号或其他字符,您可以将键盘默认为字母键盘的背面。
currentTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;