How to add Done button to Numpad in iOS using Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The iOS number pad does not include a built-in Done key, so users can get stuck with the keyboard onscreen unless your app provides another way to dismiss it. The standard fix is to attach a toolbar above the keyboard and put a Done button on that toolbar.
In UIKit, this is done through the text field or text view's inputAccessoryView. Once that accessory view is attached, the Done button can call resignFirstResponder() to dismiss the numpad cleanly.
The Basic Approach
For a UITextField, set keyboardType to a numeric keyboard and attach a UIToolbar as the accessory view:
This is the most common and reusable solution.
Why inputAccessoryView Is the Right Tool
The accessory view sits just above the keyboard and follows the first responder automatically. That makes it a better choice than placing a separate button elsewhere on the screen when the only goal is keyboard dismissal.
It also matches normal iOS behavior for forms where the keyboard type lacks a built-in action key.
Supporting Multiple Fields
If several numeric fields need the same toolbar, you can attach the same accessory view to each one and resign the current first responder generically:
Using view.endEditing(true) is convenient when you do not want to track which specific field is active.
Works for UITextView Too
The same idea also works for text views:
The dismissal action can still call view.endEditing(true) or textView.resignFirstResponder().
Choosing the Keyboard Type
If the user needs decimals or phone-style input, remember that .numberPad, .decimalPad, and .phonePad are different keyboards.
The Done toolbar solution works with all of them because it is not tied to a specific key layout. That is one reason it is better than trying to simulate a missing key on the keyboard itself.
Common Pitfalls
The biggest pitfall is looking for a property that magically adds a Done key to .numberPad. UIKit does not provide a one-line built-in switch for that keyboard type.
Another common issue is forgetting to call sizeToFit() on the toolbar. Without that, the accessory view may not size itself correctly.
Developers also sometimes target the Done button at the wrong object or forget the @objc method, which means tapping the button does nothing.
Finally, remember that keyboard dismissal is only one part of the UX. If the field needs validation or formatting, do that separately instead of overloading the Done button action with unrelated logic.
Summary
- The iOS number pad has no built-in Done key.
- The standard solution is a
UIToolbarassigned toinputAccessoryView. - Put a
.donebar button item on the toolbar and dismiss the keyboard withresignFirstResponder()orview.endEditing(true). - The same approach works for
UITextFieldandUITextView. - Use this pattern for
.numberPad,.decimalPad, and similar keyboards that lack a built-in dismissal action.

