How to display this little white x-circle in a UITextField so that users can delete text?

Some applications have this small little white circle with a gray x in a UITextField. How can I add this to a UITextField and delete the text when I click it?

+5
source share
2 answers

To add such a button, you can use the clearButtonMode UITextField property .
The code will look 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;
+18
source

Check the clearButtonMode property .

+1
source

All Articles