I want to use .phonePad
or .numberPad
keyboard.
But it has no return button. I need this.
How can I do it? I should create a custom keyboard?
I want to use .phonePad
or .numberPad
keyboard.
But it has no return button. I need this.
How can I do it? I should create a custom keyboard?
You can add an UIToolbar
above the keyboard using the UITextField
's inputAccessoryView
Assuming you are using Swift :
func setupTextfield() {
// ...
myTextField.inputAccessoryView = inputAccessoryView()
// ...
}
private func inputAccessoryView() -> UIToolbar {
let keyboardToolbar = UIToolbar()
keyboardToolbar.sizeToFit()
keyboardToolbar.isTranslucent = false
let flexBarButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace,
target: nil, action: nil)
let doneBarButton = UIBarButtonItem(barButtonSystemItem: .done,
target: self, action: #selector(UIView.endEditing(_:)))
keyboardToolbar.items = [flexBarButton, doneBarButton]
return keyboardToolbar
}
You can add toolbar at top of keyboard
- (void)viewDidLoad
{
[super viewDidLoad];
UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
toolbar.items = @[[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelAction)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneAction)]];
toolbar.barStyle = UIBarStyleBlackTranslucent;
[toolbar sizeToFit];
yourTextField.inputAccessoryView = toolbar;
}
-(void)cancelAction{
yourTextField.text = @"";
}
-(void)doneAction{
NSString *text = yourTextField.text;
}
You have to add toolbar on top of keyboard . Use InputAccessoryView property of textfield. here is complete tutorial for this
swift
https://iosdevcenters.blogspot.com/2016/01/how-to-adding-return-key-in-number.html
objective c