Action when the small cross button of UITextField is pressed

后端 未结 2 767
隐瞒了意图╮
隐瞒了意图╮ 2021-01-06 19:34

I can add a small cross button that is used to clear all the text in a single click in a UITextField with the following code.

textField.clearBut         


        
相关标签:
2条回答
  • 2021-01-06 20:02

    Use the delegate method textViewShouldClear::

    Asks the delegate if the text field’s current contents should be removed.

    - (BOOL)textFieldShouldClear:(UITextField *)textField
    

    Parameters

    textField
    

    The text field containing the text.

    Return Value

    YES if the text field’s contents should be cleared; otherwise, NO.

    Discussion

    The text field calls this method in response to the user pressing the built-in clear button. (This button is not shown by default but can be enabled by changing the value in the clearButtonMode property of the text field.) This method is also called when editing begins and the clearsOnBeginEditing property of the text field is set to YES.

    Implementation of this method by the delegate is optional. If it is not present, the text is cleared as if this method had returned YES. Availability

    * Available in iOS 2.0 and later.
    

    Declared In UITextField.h

    0 讨论(0)
  • 2021-01-06 20:12

    You can use textFieldShouldClear: delegate method to handle when user taps on clear button.

    0 讨论(0)
提交回复
热议问题