How to programmatically set iphone keyboard to show desired key set - ios

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

Related

How to replace UIPickerView with native keyboard back?

I need to dynamically change the input for UITextField: keyboard with pickerView and back (pickerView with keyboard).
I know how to substitute keyboard with pickerView - via input property of textfield.
But I don't know to substitute pickerView with keyboard back. How can I do this?
The flow is following:
user need to enter some value into textfield (typing via keyboard)
then I'll show them some clarification options via pickerView, user select any option and it will appear into textfield
then user should be able to edit the selected value in the textfield via native keyboard
Thank you
You can use,
textfield.inputView = nil;
and if you want to show keyboard directly after then you can use
[textfield becomeFirstResponder];
Hope this will work. :)

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

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.
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.
To switch the Keyboardlayout programmatically you have to mutate UITextfield's keyboardType attribute.
Try
textField.keyboardType = UIKeyboardType.NumberPad;
or
textField.keyboardType = UIKeyboardType.PhonePad;

UIKeyboardTypeURL is showing '.co.uk' instead of '.com'

I want my textfield keyboard to show a .com button. I'm in the UK and it shows a .co.uk button instead. How can I change this?
textField.keyboardType = UIKeyboardTypeURL;
It's not up to you to decide this. It's based on the user location profile.

How can I force my app to use my custom keyboard?

I've build a custom keyboard, but I don't want that the people to go to Settings > General. Select Keyboard and then click on Add Keyboard, I would like the people just open the app and when a certain text field get focused my custom keyboard appear.
How can I achieve this?
You can not do it. User must have to select keyboard from the settings. You can not force to use your keyboard by the user.
For more check the documents provided by apple for the custom keyboard : https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
There are some pros and cons also there.
You can not force the user to choose your keyboard.
If it really matter, you may add a custom view as input for your textfield, and implement your keyboard in that view.
Good luck.
Simply you can not force user to use your custom keyboard. If user select your custom keyboard form setting then they can use your custom keyboard but without selecting your custom keyboard from setting they can not use your custom keyboard.
If your textField need some special type of input then you can set keyboard for it by selecting your textField go to Attribute inspector at keyBoard type you can find some default Keyboard which is available by apple as shown in below Image:
You can use any of this keyboard from here.
And If you want to set it Programmatically you can do it this way:
yourTextField.keyboardType = .NumberPad
Here is a keyboardType property for a UITextField:
enum UIKeyboardType : Int {
case Default // Default type for the current input method.
case ASCIICapable // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
case NumbersAndPunctuation // Numbers and assorted punctuation.
case URL // A type optimized for URL entry (shows . / .com prominently).
case NumberPad // A number pad (0-9). Suitable for PIN entry.
case PhonePad // A phone pad (1-9, *, 0, #, with letters under the numbers).
case NamePhonePad // A type optimized for entering a person's name or phone number.
case EmailAddress // A type optimized for multiple email address entry (shows space # . prominently).
#availability(iOS, introduced=4.1)
case DecimalPad // A number pad with a decimal point.
#availability(iOS, introduced=5.0)
case Twitter // A type optimized for twitter text entry (easy access to # #)
#availability(iOS, introduced=7.0)
case WebSearch // A default keyboard type with URL-oriented addition (shows space . prominently).
}
Hope it will help you.

Show UIKeyboardTypeNumbersAndPunctuation and allow user to switch to text

I would like to display the UIKeyboardTypeNumbersAndPunctuation first to the user, but allow them to switch the default letter keyboard if they wish. When I set my keyboardType to UIKeyboardTypeNumbersAndPunctuation, there isn't an option to switch to the default keyboard.
Is there a keyboardType that first showing the UIKeyboardTypeNumbersAndPunctuation but still allows the user to switch?
I think you should use accessory view att the top of your keyboard, to store a button that changes your keyboardInput. https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1

Resources