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

拟墨画扇 提交于 2019-12-10 03:22:52

问题


Is there some way to have a keyboard of type UIKeyboardTypeNamePhonePad start in phone number pad mode rather than alphabetic? The keyboard works well for what I need but I'd like it to start in the "other" mode since that is more likely what the user will enter.


回答1:


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




回答2:


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




回答3:


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;



回答4:


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

[self.myTextfield setKeyboardType:UIKeyboardTypeNumberPad];


来源:https://stackoverflow.com/questions/2489939/can-keyboard-of-type-uikeyboardtypenamephonepad-be-made-to-start-in-phone-mode

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