How to add a 'Done' button to numpad keyboard in iOS
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The iOS number pad is convenient for numeric input, but it does not include a built-in return key. The standard fix is to attach a toolbar above the keyboard and place a Done button on that accessory view so the user can dismiss the keyboard cleanly.
Use inputAccessoryView
Every UITextField and UITextView can display a custom accessory view above the keyboard. For the number pad, this is the normal place to put dismissal controls.
This is the most common solution because it works with the system keyboard and avoids building a custom keypad.
Why You Cannot Add a Return Key Directly
A common misunderstanding is that the system number pad can be configured to show a return or done key. In general, that keyboard layout does not expose one. The accessory view is the supported extension point.
That is why the correct solution is not "modify the number pad," but "add controls above it."
Reuse the Toolbar Across Multiple Fields
If several fields use .numberPad, it is worth wrapping the setup in a helper.
Then use it like this:
This keeps controller code cleaner and avoids duplicating toolbar construction logic.
Think About the Full Input Flow
The Done button is only one part of the experience. Numeric-entry screens often also need validation, formatting, or navigation to the next field.
If there are several numeric fields, you can replace the single done button with Previous, Next, and Done buttons on the same accessory toolbar. The pattern stays the same; only the actions change.
That is why it helps to think of the accessory view as part of the whole form flow rather than as a one-off keyboard hack.
view.endEditing(true) Is Often Simpler
You can dismiss the active responder directly, but view.endEditing(true) is often the easiest action because it dismisses whichever text input is currently active.
That makes the code more resilient when the screen grows beyond one field.
Common Pitfalls
A common mistake is trying to force the system number pad to include a return key. The proper extension point is the accessory view.
Another issue is calling resignFirstResponder() on the wrong control. Using view.endEditing(true) is often safer.
Developers also sometimes forget accessibility and localization. If you use a custom text title instead of the system .done item, make sure it stays clear to all users.
Summary
- The iOS number pad has no built-in
Donekey. - Use an
inputAccessoryViewwith a toolbar andDonebutton. - Dismiss the keyboard with
view.endEditing(true)or the active field's responder methods. - Wrap the setup in an extension if several numeric fields need the same behavior.
- Treat the accessory view as part of the form's full input flow, not just as a dismissal trick.
Related reading
- How to add a footer to a UITableView in Storyboard
- How to add a gradient to a Button in Flutter?
- How to add a jar in External Libraries in Android Studio?
- How to add a right button to a UINavigationController?
- How to add a touch event to a UIView?
- how to add an action on UITextField return key?
- How to add an activity indicator in SwiftUI
- How to add annotations to MKMapView asynchronously?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.