UITextField will not show the clear button

I have a UITextField in which I want to display a clear button. UITextField cornerRadius has been changed and has no border. I also added a registration to the left and right of the text area. The following code leaves me without a 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 can’t get a button to display? I would appreciate any help.

Thank!

+3
source share
2 answers

Maybe you can try this

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

I think just giving how

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

You will receive a clear button when editing, and setting any radius of the angle does not affect it.

-1
source

Source: https://habr.com/ru/post/1783316/


All Articles