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
Other related/useful keypad types are:
textField.keyboardType =.numberPad
textField.keyboardType =.decimalPad
textField.keyboardType =.phonePad
精彩评论