Enabling the done button when entering in a UITextField

It’s time to think of the user experience!

When making changes to a UITextField the user may well expect a press of the done button to make the keyboard disappear. Unfortunately, this is not functionality built into iOS so has to be coded by an eager developer. In order to do this, just follow the steps below: and don’t say I never do anything for you!


  • Some understanding of using the keyboard for iOS Apps


UITextField: An object in iOS that displays an editable text area


When we press the done button on the keyboard we want the keyboard to hide. This is the same as the sender resigning the first responder designation as:

We need to add a target to our TextField in order to do this. An example of this is shown below:

Now this can be run from any sensible place (viewDidLoad is my chosen place).

Exploring further

It is possible to implement this as a subclassed UITextField, however this is left as an exercise for the reader.

Want to get in contact? Try the link here:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store