3

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

AamirR
  • 11,672
  • 4
  • 59
  • 73
Mike Hoover
  • 31
  • 1
  • 2

3 Answers3

9

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

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
2

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

Sid
  • 9,508
  • 5
  • 39
  • 60
  • Thanks for the comments. I want to use the UIKeyboardTypeEmailAddress but have the app start with the numeric portion showing and stay on that. Initially, the keyboard starts with the alphabetic characters and the user has to press the [_123] button to get to the numbers, but I want to start on the numbers and stay there even when the '+' button is pressed (normally it returns to the alphabet characters. – Mike Hoover May 16 '11 at 23:27
  • See the edit... The keyboard type you're looking for is UIKeyboardTypeNumbersAndPunctuation . How to use it is in the edited part of my answer. – Sid May 17 '11 at 00:01
0

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

enter image description here

Other related/useful keypad types are:

textField.keyboardType =.numberPad

enter image description here

textField.keyboardType =.decimalPad

enter image description here

textField.keyboardType =.phonePad

enter image description here

AamirR
  • 11,672
  • 4
  • 59
  • 73