Can keyboard of type UIKeyboardTypeNamePhonePad be made to start in phone mode?

自作多情 提交于 2019-12-05 03:54:39
futurevilla216

I believe that by setting the keyboardType property to UIKeyboardTypeNumbersAndPunctuation, you will default to the numbers and punctuation view, while still having the option of returning to the "ABC" view. Apple's documentation on it: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextInputTraits_Protocol/Reference/UITextInputTraits.html

Related question: how to show numbers in the default keyboard initially for UITextField

Anthony F

Unfortunately the answer to this question is NO, but there is a workaround.

You can use the UIKeyboardTypeNumberPad and add a custom button (e.g. https://stackoverflow.com/a/4826342/61569) to switch the keyboard to UIKeyboardTypeNamePhonePad. The challenge with this workaround is to support the keyboard styles of different versions of iOS with this custom button

The UIKeyboardTypeNumberPad does not have the 'Done' or the 'ABC' button that will allow you to toggle back and forth between default keyboard and the NumberPad. Now you can choose to go with what @Anthony F suggested but remember you risk the chance of loosing the custom 'Done' button everytime Apple releases newer versions of iOS and move their keyboard window around. To achieve what you want, your best bet will be to set your keyboardType to UIKeyboardTypeNumbersAndPunctuation. This way, you have your keyboard NumberPad loaded up automatically when your view load and have the 'ABC' button also present to be able to toggle between the default keyboard also if you want.

self.myTextfield.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

In the textfield in question, You set the kind of keyboard you would like it to "activate":

[self.myTextfield setKeyboardType:UIKeyboardTypeNumberPad];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!