How to set number side as default (while keyboard

2019-04-21 06:01发布

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:

screenshot

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

screenshot

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.

screenshot

2条回答
该账号已被封号
2楼-- · 2019-04-21 06:57

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

Try

textField.keyboardType = UIKeyboardType.NumberPad;

or

textField.keyboardType = UIKeyboardType.PhonePad;
查看更多
Explosion°爆炸
3楼-- · 2019-04-21 07:05

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.

查看更多
登录 后发表回答