How to set number side as default (while keyboard is open) of name phone pad keyboard type

回眸只為那壹抹淺笑 提交于 2019-12-10 01:48:00

问题


Right now when the keyboard launches on my application it defaults to the letter side showing an alphabetical keyboard.

Question will be listed below images

Refer to image below:

This is good. Clicking 123 will show the number side.

The Question:

However, I want to by default show the number side and still be able to switch back to the letter side later WHEN THE KEYBOARD IS OPEN. How do I do this?

Setting the keyboard programmatically to a different type is NOT the answer!

For example: User clicks in the text field, keyboard pops up and defaults to let's say the ABC side. The user can click 123 to switch. This is what I want. If the ability to switch while the keyboard is open is taken away it defeats the point of this question.

So if the Name Phone Pad keyboard defaults to the ABC side initially. I want it to default to the 123 side that way while the keyboard is still open it can switch to ABC again when the user clicks ABC.

I want to do this because I have different settings for how to search for barcodes. Either by name of the product or number based on settings the user set about how to index results. This way if they are sorting by number it suggests numbers first, BUT they can still go back to searching by alphabetical if they wanted by clicking the ABC button on the keyboard.

Here is the current setting for my keyboard.


回答1:


keyboardType is property for a UITextField.

textField.keyboardType = UIKeyboardType.UIKeyboardTypeNumberPad

and

textField.keyboardType = UIKeyboardType.UIKeyboardTypeDefault

is how you can switch between the two modes programatically. Hope that helps.




回答2:


To switch the Keyboardlayout programmatically you have to mutate UITextfield's keyboardType attribute.

Try

textField.keyboardType = UIKeyboardType.NumberPad;

or

textField.keyboardType = UIKeyboardType.PhonePad;


来源:https://stackoverflow.com/questions/36543544/how-to-set-number-side-as-default-while-keyboard-is-open-of-name-phone-pad-key

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