I'm wondering if there is a way to have the UITextField clear button 'always visible'
textfield.clearButtonMode = UITextFieldViewModeAlways;
doesn't seem to work .. and if it is possible to dismiss the keyboard using the button?
Thanks in advance.
The first two are standard to the iOS system: Stop editing the note, and the keyboard will disappear. This requires clicking somewhere away from the text. Swipe your finger downwards beginning just above the keyboard, so that you catch the keyboard as you move.
An object that displays an editable text area in your interface.
If you're supporting only iOS 15 and later, you can activate and dismiss the keyboard for a text field by focusing and unfocusing it. In its simplest form, this is done using the @FocusState property wrapper and the focusable() modifier – the first stores a Boolean that tracks whether the second is currently focused.
The onEditingChange parameter take a closure with a single Bool parameter, if it is true then the TextField has begun to edit the parameter. In your closure check the value of the parameter and clear the TextField variable if it is true.
Like mentioned before it seems apple is setting the textfield focus after you clear the field.
The solution is quite simple. Just clear the field yourself, resignFirstResponder and return NO
-(BOOL)textFieldShouldClear:(UITextField *)textField
{
textField.text = @"";
[textField resignFirstResponder];
return NO;
}
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