本文介绍了如何在UITextField中添加自定义清除按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调整 UITextField 的默认清除按钮的大小.经过大量的搜索后,我知道没有办法对其进行修改.

I want to resize the default clear button of UITextField. After I googled a lot, I came to know there is no way to modify it.

所以我决定使用自定义选项,即在文本字段中添加 UIButton .我从S.O中找到了一些代码,但对我来说没有用.这些是我引用的链接.

So I decided to go with Custom option ie, by adding UIButton to text field.I found some code from S.O, but nothing works for me. These are the links which I referred.

所以请提出一些与 UITextField

任何帮助将不胜感激.

谢谢.

推荐答案

除了jake9115响应外,您还可以使用 UITextFieldDelegate 回调.

In addition to the jake9115 response, you can emulate the clearbutton behavior by using the UITextFieldDelegate callbacks.

您可以通过以下方式尝试:
在调用 -textFieldDidBeginEditing :
时显示按钮调用 -textFieldDidEndEditing:时隐藏按钮
如果-(BOOL)textFieldShouldClear:(UITextField *)textField 中textField的 text length 为0,则隐藏按钮.

You can try in this way:
Show the button when -textFieldDidBeginEditing: is called
Hide the button when -textFieldDidEndEditing: is called
Hide the button if in -(BOOL)textFieldShouldClear:(UITextField*)textField the length of the textField's text is 0.

这篇关于如何在UITextField中添加自定义清除按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:06