Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textField.clearButtonMode = /* whatever */ doesn't work

I'm creating a textField and adding it to a view like this:

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(/*blah blah */)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.clearButtonMode = UITextFieldViewModeAlways;

[otherView addSubview:textField];

The text field is rendered as expected in otherView, but the clear button is never rendered, no matter what value I assign to clearButton. Anyone know what might be causing this?

like image 955
Ben Collins Avatar asked Jan 26 '11 21:01

Ben Collins


1 Answers

The answer is that UITextField.clearButtonMode works. When the text field has a value, the button is there. I guess I assumed "Always" means "Always", when it really means, "when .text != nil".

like image 113
Ben Collins Avatar answered Oct 14 '22 10:10

Ben Collins