How to show Done button on iOS number pad keyboard?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
The iOS numberPad keyboard is intentionally minimal: it gives you digits, but no Return or Done key. That often surprises people the first time they build a numeric form. The standard fix is to keep the system keyboard and attach a small accessory toolbar above it with a Done button that dismisses the current responder.
Why returnKeyType does not solve it
On a normal text keyboard, setting returnKeyType = .done changes the label and behavior of the return key. On numberPad and decimalPad, there is no return key to configure, so that property has no visible effect.
This is an important design constraint in UIKit: you cannot inject extra keys into the system number pad. What you can customize is the accessory area above the keyboard through inputAccessoryView.
UIKit solution with UIToolbar
The usual approach is to create a UIToolbar, add a flexible spacer and a Done button, then assign the toolbar to the text field's inputAccessoryView.
This works well because it preserves the familiar system keyboard and adds only the missing action.
Reusing the pattern across multiple fields
Most forms have more than one numeric input, so it is worth moving the toolbar setup into an extension. That keeps the view controller smaller and makes the behavior consistent across the app.
Usage stays simple:
If you have several fields and want a Next button as well, the same toolbar pattern scales easily. You can add another UIBarButtonItem and move focus to the next responder before finishing with Done.
SwiftUI uses a keyboard toolbar
In SwiftUI, you do not usually set inputAccessoryView directly. The modern equivalent is a toolbar item placed on the keyboard.
The idea is the same as UIKit: keep the stock number pad and add the dismissal control above it.
Common Pitfalls
A common mistake is expecting returnKeyType to magically add a Done key to numberPad. It will not, because that keyboard layout has no return key to relabel.
Another frequent bug is wiring the toolbar correctly but forgetting to dismiss the responder. If the button does not call resignFirstResponder(), it looks right and still does nothing.
Some teams overbuild this by creating a custom keyboard. That usually gives you more code, more testing burden, and less native behavior than a simple accessory toolbar.
Also test decimalPad separately if your form allows decimal input. It has the same no-Done-key limitation, so it typically needs the same solution.
Summary
- The iOS number pad does not include a built-in Done key.
- '
returnKeyTypedoes not help because the keyboard layout has no return button.' - In UIKit, attach a
UIToolbartoinputAccessoryView. - Make the Done action call
resignFirstResponder()to dismiss editing. - In SwiftUI, use a keyboard toolbar item for the same behavior.
Related reading
- How to show soft-keyboard when edittext is focused
- How to show the loading indicator in the top status bar
- How to silence a warning in Swift?
- How to simulate Android killing my process?
- How to solve error running pod install in flutter on mac?
- How to solve String interpolation produces a debug description for an optional value; did you mean to make this explicit? in Xcode 8.3 beta?
- How to specify the JDK version in Android Studio?
- How to split filename from file extension in Swift?
.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.