我正在创建一个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
”。