Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom action for clear button of UITextfield in swift

I have a UITextfield which has clear button enabled only while editing and it as shown in image attached. enter image description here

What i need is when i tap on clear button of UITextfield it should do few custom activity along with clearing the UItextfield. As of now it only clears the UITextField only. It is not specific to clear/ dismiss keyboard.

Thanks

like image 992
sia Avatar asked Sep 28 '17 04:09

sia


1 Answers

You can use this UITextFieldDelegate method. Don't forget to set delegate for the textfields. UITextFieldDelegate

func textFieldShouldClear(_ textField: UITextField) -> Bool {
    print("text cleared")
    //do few custom activities here
    return true
  }
like image 90
RajeshKumar R Avatar answered Nov 10 '22 01:11

RajeshKumar R