开发者

How to programmatically set iphone keyboard to show desired key set

开发者 https://www.devze.com 2023-03-06 02:24 出处:网络
I am programming an iPhone app that I want a text field where the user can add numbers from the keyboard and add them on the fly, ie, the user might type \"1.5+2.4+6.3+.063\" and as the user types add

I am programming an iPhone app that I want a text field where the user can add numbers from the keyboard and add them on the fly, ie, the user might type "1.5+2.4+6.3+.063" and as the user types additional numbers and plus signs the total is displayed immediately.

The problem is starting on and keeping the keyboard in the 123 mode after the user types a + sign (using email 开发者_运维技巧keyboard because it has the numbers and the plus sign on the same view).

How can I start the email keyboard on the _123 screen and keep it there?

Thanks! Mike


use below code to set the keyboard type

myTextField.keyboardType = UIKeyboardTypeNumberPad;

All the keyboard type is define in UITextInputTraits protocol, which is implemented by UITextField


Depending on what textfield you want to set it for you go:

[textField setKeyboardType:(UIKeyboardType)];

Where UIKeyboardType could be any of the following: UIKeyboardTypes

***EDIT

In your case you would do:

[textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];

***EDIT


No, I could not find a way to programmatically change keyboard modes to 123 or #+=.

But if you want the default keyboard start as if user had pressed the 123 button on keypad, your only choice is:

textField.keyboardType = UIKeyboardType.numbersAndPunctuation

Here is how numbersAndPunctuation keypad will be presented

How to programmatically set iphone keyboard to show desired key set

Other related/useful keypad types are:

textField.keyboardType =.numberPad

How to programmatically set iphone keyboard to show desired key set

textField.keyboardType =.decimalPad

How to programmatically set iphone keyboard to show desired key set

textField.keyboardType =.phonePad

How to programmatically set iphone keyboard to show desired key set

0

精彩评论

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

关注公众号