Cocoa touch UITextField赢得';不显示清除按钮

Cocoa touch UITextField赢得';不显示清除按钮,cocoa-touch,uitextfield,Cocoa Touch,Uitextfield,我有一个UITextField,我想在其中显示一个clear按钮。UITextField的cornerRadius已修改,并且没有边框。我还在文本区域的左侧和右侧添加了填充。下面的代码没有清除按钮 searchField.layer.cornerRadius = 15; searchField.clearButtonMode = UITextFieldViewModeAlways; UIView *padding = [[UIView alloc] initWithFrame:CGRectMak

我有一个UITextField,我想在其中显示一个clear按钮。UITextField的cornerRadius已修改,并且没有边框。我还在文本区域的左侧和右侧添加了填充。下面的代码没有清除按钮

searchField.layer.cornerRadius = 15;
searchField.clearButtonMode = UITextFieldViewModeAlways;
UIView *padding = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 20)];
searchField.leftView = padding;
searchField.leftViewMode = UITextFieldViewModeAlways;
searchField.rightView = padding;
searchField.rightViewMode = UITextFieldViewModeAlways;
[padding release];
[searchField addTarget:self action:@selector(textFieldDidChange) forControlEvents:UIControlEventEditingChanged];
searchField.userInteractionEnabled = YES;
有人知道我为什么不能让按钮显示吗? 我非常感谢你的帮助

谢谢

也许你可以试试这个

[textFieldAddress_ setLeftView:buttonBookmark_];
[textFieldAddress_ setLeftViewMode: UITextFieldViewModeAlways];
[textFieldAddress_ setRightView:buttonReloadAndCancel_];
[textFieldAddress_ setRightViewMode: UITextFieldViewModeUnlessEditing];
textFieldAddress_.clearButtonMode = UITextFieldViewModeWhileEditing;

我认为只要付出就可以了

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

在编辑和设置任何角半径时,您都可以清除按钮。

这太棒了。谢谢这对我很管用。苹果的文档难道不应该指出拥有一个rightView将覆盖clear按钮吗?