How do I programmatically switch keyboard layouts on the iPad? - ios

I am having trouble finding resources on this, it may be a keyword thing. I am developing for the iPad, and I have text fields with numbers. I understand there is not a dedicated numeric keyboard, I wish to know if there is a way after the keyboard shows to programmatically switch to the numeric view.
I have seen other apps do this, so I don't think it is a matter of 'if' as much as 'how'. How do I programmatically switch keyboard layouts on the iPad?

Set your text field's keyboardType property to UIKeyboardTypeNumberPad or UIKeyboardTypeNumbersAndPunctuation. I think on an iPad they will currently both give you the numeric+punctuation keyboard, but perhaps a future version of iOS will have a numeric only keyboard, so you should use request one if it's more appropriate.
If you are creating the text field programatically:
UITextField *numericTextField = [[UITextField alloc] initWithFrame:CGRectMake(100, 10, 185, 30)];
numericTextField.adjustsFontSizeToFitWidth = YES;
numericTextField.keyboardType = UIKeyboardTypeNumberPad;
[parentView addSubview:numericTextField];
Or if you're using interface builder, there is a setting in the inspector pane to control the keyboard type.

Related

Is there a way to make the iOS default keyboard show the numbers version first? [duplicate]

Created a UITextField for "Postal Code/ZIP" field with a keyboardType of UIKeyboardTypeDefault. I would like to use the default keyboard but want the numbers & symbols to be shown by default as apposed to letters.
Apple does this when you are entering addresses in the Contacts.app.
Anyone know how to get this accomplished?
You want the UIKeyboardTypeNumbersAndPunctuation keyboard type.
And a code example of what executor21 said:
UITextField* txt = [[UITextField alloc] init];
txt.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

Add UILabel to the left side of a UITextField

I'm trying to consolidate screen space in my iPhone app by putting label text inside of a UITextField that will be uneditable. It will tell the user what to put into the text field. Here is an example of an app that does exactly what I want to do.
I have done my research and found some code to mimic this to some extent.
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 80, 40)];
label.text= #"Exerise Name:";
label.font = [UIFont fontWithName:#"Arial" size:12];
[label setTextColor:[UIColor blueColor]];
_txtExerciseName.leftViewMode = UITextFieldViewModeAlways;
_txtExerciseName.leftView = label;
[self.view addSubview:_txtExerciseName];
This is inside viewDidLoad. The code yields something like this:
Obviously with styling and tweaking this might work but I was wondering if there is a better way to do this that I am not seeing. If someone has any tips, ideas, or code samples to get me going in the right direction I would really appreciate it.
I saw a really cool solution to this problem. The placeholder text is moved to the top of the textfield when the keyboard comes up/becomes the first responder, then disappears when the textfield resigns the first responder.
Implementations
Objective-C
Swift
The effect you're trying to mimic is almost certainly done by:
Creating what looks like a text box image in an image editing app, importing into your project -- you could also do it via slices so you can create any width field background.
Place the aforementioned image where you want the label and text field
Place a borderless UILabel and a borderless UITextField in the appropriate spot above the image you just dropped.
That should do it. No code changes necessary.

Customize uikeyboardtype with #gmail.com and numbers

I want to create a UIKeyboard type that will look like the following.
This app is only for iPad and none of the default keyboard type seem to match.
Any suggestions for adding buttons to the keyboard type?
I may be wrong, but what that looks like is the standard keyboard with a custom toolbar on top. It was most likely done using the inputAccessoryView property for the textfield:
[textField setInputAccessoryView:inputAccView];
Here is where I took the example from.
As far as I am aware, this is not supported in a super easy way by default iOS system keyboards.
However, you can specify your own UIView as an "input accessory view" for a text field.
Specifically, look at this method in the UITextField documentation:
inputAccessoryView.
So you should just be able to create a UIView, style it to look very similar to the usual system keyboard UI, add UIButtons, and set it as the "input accessory view"
But you will have to do your own work to make the background of the accessory view and the buttons on it fit well with the system keyboard.

Transparent Keyboard?

almost finished my App. All calculations, ..... are now working.
As I have several Text Fields on the view and when I'm showing keyboard, I cannot see what I typing Field it is hidden by the keyboard.
Do you have a method for showing transparent keyboard then people will be able to see by transparency.
Regards
You'll need to add the following code in your .m file for each view you want to add the transparent keyboard to:
- (void)viewDidLoad {
[super viewDidLoad];
textField1.keyboardType = UIKeyboardTypeDecimalPad;
textField1.keyboardAppearance = UIKeyboardAppearanceAlert;
textField2.keyboardType = UIKeyboardTypeDecimalPad;
textField2.keyboardAppearance = UIKeyboardAppearanceAlert;
}
textField1 and textField2 are just examples. you need to add these 2 lines for each field. It's guaranteed way, I have 2 apps with these and just updated them 2 weeks ago and they were never rejected.
****You should change to the keyboard type you want.**
You should read the "Keyboard Management" section of the "Text, Web and Editing Programming Guide" in Apple documentation.
In the "Moving Content That Is Located Under the Keyboard" paragraph, they explains how to manage the keyboard properly and how to scroll your view so that the current text field is always visible and never hidden by the keyboard.
(source: apple.com)
There's no such thing as a transparent keyboard. You need to move your text field so that it is visible when the keyboard is displayed.

How to stop my Custom Keyboard from 'floating' or being undocked on iPad

I have a custom Keyboard that gets displayed for a certain UITextField when I set the textField's inputView to my KeyboardView. The keyboard works fantastically well but it has become apparent that the keyboard will 'float' if the user has previously undocked the built in Apple Keyboard or indeed split it.
I have searched for many hours for a way to ensure my custom keyboard does not act like this and instead stays docked to the bottom of the screen regardless as to whether the user has previously undocked the built in Apple Keyboard.
self.keyboardInputView = [[[KeyboardInputViewController_iPad alloc]
initWithNibName:#"KeyboardInputViewController_iPad"
bundle:[NSBundle mainBundle]] autorelease];
self.keyboardInputView.delegate = self;
self.keyboardInputView.keyboardTextField = myTextField;
myTextField.inputView = self.keyboardInputView.view;
[myTextField becomeFirstResponder];
You shouldn't do this, neither is there a way to do so.
You cannot override user settings with a custom keyboard, especially not the ones that can improve the accessiblity of a user interface.
You could include a warning in the tutorial that your keyboard works best while being locked to the bottom, but you must ask yourself the question whether this is good UX or not. I would say the latter.

Resources