Custom UITextField clear button

前端 未结 7 752
渐次进展
渐次进展 2021-01-31 08:16

Is it possible to customize the image of the clear button in a UITextField? I have a dark textfield background and the \"x\" is not visible enough.

7条回答
  •  花落未央
    2021-01-31 08:58

    You can set your own custom clear button to the text field's rightView property. Make sure set the rightViewMode property to UITextFieldViewModeWhileEditing or UITextFieldViewModeAlways, whatever makes sense for your case.

    If the button's position isn't right for your need, you can subclass UITextField and override the rightViewRectForBounds: method.

    The documentation says the default for the clearButtonMode property is UITextFieldViewModeNever, but I suspect Interface Builder may set it to UITextFieldViewModeWhileEditing - Make sure you set it to the "never" value so it doesn't appear.

    All these properties are documented in UITextField Class Reference.

提交回复
热议问题