开发者

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

开发者 https://www.devze.com 2022-12-23 22:16 出处:网络
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

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 th开发者_JS百科e user will enter.


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


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];
0

精彩评论

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

关注公众号