Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show "Done" button on iOS number pad keyboard?

There is no "Done" button on the .numberPad Keyboard Type. When a user finishes entering numeric information in a text field, how can I make the number pad disappear?

I could get a "Done" button by using the default keyboard, but then users would have to switch to the numeric keys in order to input numbers. Is there a way to show a "Done" button on the number pad?

like image 838
Chilly Zhong Avatar asked Feb 25 '09 02:02

Chilly Zhong


People also ask

How do I add a Done button to a number keypad in Swift?

addDoneKeyboardButton() — creates the keyboard done button using UIToolbar. Inside the toolbar, we create a UIBarButtonItem. You can name the button however you want, and you can add multiple buttons (depending on your needs). In other words, use this function to customize the toolbar.

How do I get my iPhone keyboard to show numbers?

If a keyboard isn't already visible, tap the Show Keyboard button , then tap the Formula Keyboard button to begin editing a formula. To quickly enter a number or symbol on an iPad, drag down on a key and then lift your finger, or switch to the numeric keyboard on iPhone.

How do you use the keys on number pad?

To activate the number pad, find the number lock key (usually labeled NumLock, Num Lk, or Num). After locating it, look for the Fn or Alt key. If either the Fn or Alt key's color matches the alternate numbers, press it in conjunction with the number lock key.


1 Answers

Another solution. Perfect if there are other non-number pad text fields on the screen.

inputAccessoryView

- (void)viewDidLoad {     [super viewDidLoad];      UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];     numberToolbar.barStyle = UIBarStyleBlackTranslucent;     numberToolbar.items = @[[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],                          [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],                          [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)]];     [numberToolbar sizeToFit];     numberTextField.inputAccessoryView = numberToolbar; }  -(void)cancelNumberPad{     [numberTextField resignFirstResponder];     numberTextField.text = @""; }  -(void)doneWithNumberPad{     NSString *numberFromTheKeyboard = numberTextField.text;     [numberTextField resignFirstResponder]; } 
like image 200
Luda Avatar answered Sep 28 '22 06:09

Luda