我正在创建一个textField并将其添加到这样的 View 中:

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

[otherView addSubview:textField];

文本字段将按预期的方式在otherView中呈现,但是无论我为clearButton分配什么值,都不会呈现clear按钮。有人知道这可能是什么造成的吗?

最佳答案

答案是UITextField.clearButtonMode有效。当文本字段具有值时,按钮在那里。我想我以为“Always”始终是“Always”,而实际上是“何时.text != nil”。

10-05 20:22
查看更多