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.
Related
I Created a keyboard extension like this:
But I don't know where to define my custom keyboard to be a numeric pad.
If any number type textfield tapped by user, the iOS default numeric pad will present with no switch button to my custom numeric pad.
The question is:
How to define my custom keyboard to be a numeric pad?
From Apple's docs Custom Keyboard:
Your custom keyboard is also ineligible to type into so-called phone pad objects, such as the phone number fields in Contacts. These input objects are exclusively for strings built from a small set of alphanumeric characters specified by telecommunications carriers and are identified by having one or another of the following two keyboard type traits:
UIKeyboardTypePhonePad
UIKeyboardTypeNamePhonePad
When a user taps in a phone pad object, the system temporarily replaces your keyboard with the appropriate, standard system keyboard. When the user then taps in a different input object that requests a standard keyboard via its type trait, your keyboard automatically resumes.
So, it looks like you cannot do what you're asking.
Right now when using textField.keyboardType = .namePhonePad, it will automatically start out showing the alpha keyboard, and you then have to press the number toggle to see the number pad. Is there any way to reverse that and have the number pad show first as the default and then be able to manually toggle to the alpha keyboard?
I know it's possible to create a custom button to be able to toggle the keyboard type, as well as changing the keyboard type based on what they type into the text field, but I just want a way to change its default first keyboard.
I put a textfield on a view and if I type the textfield a keyboard will be shown. I can click on the input change button on the keyboard to change input language to emoji. Now I want to let the keyboard shown with emoji input as the default one. How can I make it on ios with swift?
No this is not possible - user can only change their language in the settings.
The Emoji keyboard is effectively a language setting that the user has to make and we cannot influence that.
There is a keyboardType property for a UITextField:
typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space # . prominently).
UIKeyboardTypeDecimalPad, // A number pad including a decimal point
UIKeyboardTypeTwitter, // Optimized for entering Twitter messages (shows # and #)
UIKeyboardTypeWebSearch, // Optimized for URL and search term entry (shows space and .)
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
} UIKeyboardType;
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;
I have an input field the user needs to fill with an alphanumeric code. The keyboard the user uses to type the code has a dynamic return button that changes to "send" as he writes some text on the field. When the field is empty the return button has the default value.
To dynamically change the return button type I use the following code:
if([textField.text isEqualToString:#""])
{
textField.returnKeyType = UIReturnKeyDefault;
}
else
{
textField.returnKeyType = UIReturnKeySend;
}
[textField reloadInputViews];
However this has the following drawback: since the code is alphanumeric, the user may be typing numbers, and yet the keyboard will always switch back to the letter keyboard, so to type more than one number in a row he will need to be continuously switching to number keyboard.
Is there any way to dynamically change the return key of a keyboard as the user types but to preserve the keyboard state to letters or numbers keyboard?
I think this is not a bug on Apple's side, more a missing implementation of API for the keyboard. With the new iOS8 API you might want to create your own keyboard returning the UIKeyboardType.
For iOS7 I worked around by inspecting the views of the keyboard. Use the US2KeyboardType CocoaPod or the source:
https://github.com/ustwo/US2KeyboardType
As Martin noted above, it's not a bug on Apple's side, but on my side. However I'll be posting the solution I've found since it is the one that solves that particular problem:
Instead of manually changing the return key type when there is text on the text field, Apple provides us with a property called enablesReturnKeyAutomatically that when set to YES it automatically manages the issue, enabling and disabling the return key depending on whether there is text or not in the text field.
Therefore you don't need to modify the returnKeyType property, and thus, no calling to reloadInputViews is required, so the keyboard doesn't change back to its original state.