Clear Text Field

I wanted to know how would I make so that when a user taps on a text field it clears the text already in it?

Accepted Reply

Just in IB, select Clear on Editing.


Select the Attributes inspector for the textField.


In the first section, you have Clear button

Below, select Clear when editing begins.

But it could be more comfortable for user to let him/her choose : in this case, select Clear Button : appears or is always visible.

Replies

Just in IB, select Clear on Editing.


Select the Attributes inspector for the textField.


In the first section, you have Clear button

Below, select Clear when editing begins.

But it could be more comfortable for user to let him/her choose : in this case, select Clear Button : appears or is always visible.

I would I get it so that if the user doesn't type anything the text goes back?

If you ask for "Clear when editing begins", text disappears as soon as user taps on field. And if he types nothing, it remains empty.


You have 2 solutions :

- let user choose to clear with "Clear Button"

- save the former content of the textField and restore it if nothing was typed.

Did that work ?


I forgot to say that restoring the former content should be in the IBAction for end editing, if textFirld is empty on exit.