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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With