How to get keyboard with Next, Previous and Done Button?
-(BOOL)textFieldShouldBeginEditing: (UITextField *)textField
{
UIToolbar * keyboardToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
keyboardToolBar.barStyle = UIBarStyleDefault;
[keyboardToolBar setItems: [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Previous" style:UIBarButtonItemStyleBordered target:self action:@selector(previousTextField)],
[[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleBordered target:self action:@selector(nextTextField)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(resignKeyboard)],
nil]];
textField.inputAccessoryView = keyboardToolBar;
}
- (void)nextTextField {
if (textField1) {
[textField1 resignFirstResponder];
[textField2 becomeFirstResponder];
}
}
-(void)previousTextField
{
if (textField2) {
[textField2 resignFirstResponder];
[textField1 becomeFirstResponder];
}
}
-(void)resignKeyboard {
[textField1 resignFirstResponder];
[textField2 resignFirstResponder];
}
I just created a class called BSKeyboardControls
which makes it very easy to add the controls to a keyboard. The class, instructions and example code can be found here at GitHub.
The controls works for text fields and text views and are optimized for both iPhone and iPad.
You'll find the answer on this other post. I checked the iOS Library and the inputAccessoryView of a UITextField is exactly what you're looking for !
Hope this helps !
I have a utility class that basically does this for you.
https://github.com/kalvish21/CustomKeyboard
The idea is very simple. You have to add an accessory tool bar with bar button items on it. There's a delegate which defines where what that button will do.