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?
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.
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.
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.
Another solution. Perfect if there are other non-number pad text fields on the screen.
- (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]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With