如何在 iPhone 上默认显示数字键盘?
我正在尝试以下操作,但没有运气。当用户单击 UiTextfield 时,我需要自动将键盘视图更改为数字视图,这可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
UITextInputTraits
协议(其中UITextField
符合)具有UIKeyboardType
类型的keyboardType
属性。The
UITextInputTraits
protocol (whichUITextField
conforms to) has akeyboardType
property of typeUIKeyboardType
.这也可以在 Interface Builder 中完成:
This could be done in the Interface Builder as well:
UITextField 符合 UITextInputTraits 协议,这意味着它具有可以设置的 KeyboardType 属性。
您还可以通过界面生成器进行设置。从文本输入特征将键盘设置为数字键盘,仅此而已。
UITextField conforms to UITextInputTraits protocol which means it has keyboardType property which you can set.
You can also set it via interface builder. From the text input traits set the keyboard to number pad and that's all.
我们也可以通过界面方法获取它。选择文本字段并转到属性检查器并从键盘下拉框中更改键盘类型。
We can get it by interface approach also.Select the text field and go to attribute inspector and change the keyboard type from the keyboard drop down box.
如果您想要显示数字键盘,但还需要能够使用小数点、货币符号或其他字符,则可以将键盘默认设置为字母键盘的背面。
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.
最好始终编写父类
UIKeyboardType
,然后继续使用键盘枚举numberPad
it is a good practice to always write the parent class
UIKeyboardType
and then continue with the keyboard enumnumberPad