如果退格已完全清除文本字段,如何删除清晰图像?

时间:2014-03-22 13:17:25

标签: ios iphone objective-c

我正在制作文字游戏当用户输入一个字母(任意字母)时,我会在文本字段上显示一个明文按钮:

清除按钮:

- (IBAction)btnclear:(id)sender {
NSString *oldString = _textbox.text;
NSString *newString;
newString = [oldString substringFromIndex: _textbox.text.length];
[_textbox setText:newString];
[_textXclear setHidden:YES];

图片在这里:https://9fcf3c93-a-62cb3a1a-s-sites.googlegroups.com/site/foreversantorini/home/Screen%20Shot%202014-03-22%20at%2015.02.48.png?attachauth=ANoY7cqysJ7x47s68f3dHMQpOmGPzwDDQ-hFotctSaKiA1OHYlZPu8BDnJEtD1oa3I3q335la9h13jZNftExDJrv7I-8WHmdbJ1mVEd-X1N50Nb3B_ogEsG2w3r2Q5SyLu-NwykqyNF4X7cocvrwkJpwYl31W26olIXPbhl0Z21j5gePDsd5lB5lJDbr1_543eUVKW9-qJOgTI-w4v2ET0vcnQw0EXbLNtQL81H1YXiyCutsPLNt426ohWUT8ooAgSXdziKdW5TE&attredirects=0

我还有一个退格按钮,可以在这里逐个删除字母:

- (IBAction)btnback:(id)sender {
NSString *backspace = _textbox.text;
int lengthofstring = backspace.length;
if(lengthofstring > 0)
backspace = [backspace substringToIndex:lengthofstring -1];
_textbox.text = backspace;

问题是当退格按钮清除所有文本时,清晰按钮图像仍保留在屏幕上!

额外信息:清除按钮的属性是_textXclear

1 个答案:

答案 0 :(得分:0)

在界面构建器的文本字段设置中,您可以设置清除按钮设置,这可以解决您的问题吗?

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/clearButtonMode

enter image description here