UITextField不会显示清除按钮

时间:2011-01-04 00:24:05

标签: cocoa-touch uitextfield

我有一个UITextField,我想在其中显示一个清除按钮。 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;

有谁知道为什么我无法显示按钮? 我很感激任何帮助。

谢谢!

2 个答案:

答案 0 :(得分:5)

也许你可以试试这个

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

答案 1 :(得分:-1)

我认为只是通过给予

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

在编辑和设置任何角落半径时,您将获得清除按钮不会影响它。