Ricky D'Amelio
Ricky D'Amelio

Reputation: 113

UITextField won't show clear button

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!

Upvotes: 3

Views: 3600

Answers (2)

Hyder Ali
Hyder Ali

Reputation: 31

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.

Upvotes: 0

Slavik
Slavik

Reputation: 1083

Maybe you can try this

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

Upvotes: 5

Related Questions