views:

24

answers:

2

Some apps have this nice little white circle with an gray x in there UITextField. How can I add this to an UITextField and delete the text when it is tapped?

+1  A: 

Check out the clearButtonMode property.

Eiko
+1  A: 

To add a button like this, you can use the clearButtonMode property of an UITextField.
The code will be like this:

// Show cancel button never
textField.clearButtonMode = UITextFieldViewModeNever;  

// Show cancel button only when you're editing text in textField
textField.clearButtonMode = UITextFieldViewModeWhileEditing;  

// Show the cancel button only when you aren't editing the text
textField.clearButtonMode = UITextFieldViewModeUnlessEditing;

// Show always the cancel button
textField.clearButtonMode = UITextFieldViewModeAlways;
Matthew