peter61
peter61

Reputation: 279

How to enable the "return button" in a UITextField keyboard?

When I start editing a UITextField, I have the "Clear When Editing Begins" option checked so it starts off with no text. However, the "Return" button is grayed out until you type at least one character.

I've seen other iphone apps where the "Return" button is not grayed out (and if you press it with no text, then it goes back to what the text used to be). How is this done?

Upvotes: 17

Views: 16077

Answers (2)

Rudolf Adamkovič
Rudolf Adamkovič

Reputation: 31486

Interface Builder folks uncheck Auto-enable Return Key in Attributes Inspector. :)

Upvotes: 12

Endemic
Endemic

Reputation: 1540

UITextView and UITextField implement the UITextInputTraits Protocol. The protocol specifies a property called enablesReturnKeyAutomatically. Here's the description from the UITextInputTraits reference:

The default value for this property is NO. If you set it to YES, the keyboard disables the return key when the text entry area contains no text. As soon as the user enters any text, the return key is automatically enabled.

So, setting the property to NO after loading the TextField should do the trick.

Upvotes: 42

Related Questions