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;
有谁知道为什么我无法显示按钮? 我将不胜感激任何帮助。
谢谢!
I have a UITextField in which I want to display a clear button. The UITextField's cornerRadius has been modified and has no border. I have also added padding to the left and right of the text area. The following code leaves me with no clear button.
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;
Does anyone know why I'm unable to get the button to show?
I'd appreciate any help.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许你可以尝试这个
Maybe you can try this
我认为在编辑和设置任何角半径时只要给出“as
you'll get clear”按钮就不会影响它。
I think just by giving as
you 'll get clear button while editing and setting any corner radius does not affect it.