Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enabling the "return button" in a UITextField keyboard (objective-c/iphone)

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?

Thanks.

like image 676
peter61 Avatar asked May 23 '10 03:05

peter61


People also ask

Where is the return button on the iPhone keyboard?

Type in the text as you desire and when you're reading to insert a line break, tap on the “123” key at the bottom-left of the keyboard. This will give you access to the num pad. Here, you'll find the “return” key at the bottom-right corner of the keyboard, next to the space bar.

How do I turn on the return button on my keyboard?

In most cases, you can just find the Enter key on the keyboard. It usually happens to the Windows computer because Microsoft Windows treats these two keys the same. When you want to use the return key, you can just try the Enter key.


2 Answers

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.

like image 128
Endemic Avatar answered Sep 17 '22 17:09

Endemic


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

like image 20
Rudolf Adamkovič Avatar answered Sep 19 '22 17:09

Rudolf Adamkovič