3

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!

2 Answers 2

5

Maybe you can try this

[textFieldAddress_ setLeftView:buttonBookmark_]; [textFieldAddress_ setLeftViewMode: UITextFieldViewModeAlways]; [textFieldAddress_ setRightView:buttonReloadAndCancel_]; [textFieldAddress_ setRightViewMode: UITextFieldViewModeUnlessEditing]; textFieldAddress_.clearButtonMode = UITextFieldViewModeWhileEditing; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thats awesome. Thanks! That worked for me. Shouldn't Apple's docs point out that having a rightView will override the clear button?
0

I think just by giving as

textField.clearButtonMode = UITextFieldViewModeWhileEditing; 

you 'll get clear button while editing and setting any corner radius does not affect it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.