NSTextField Clear Button
On the iPhone a UITextField
can have a clearButtonMode set to show a small clear button (X) at the 开发者_运维问答end of a text input. Similarly, on the Mac the NSSearchField
has a nice clear button on it at the end. My question is - is there a way to enable this on a normal NSTextField
?
There's nothing built-in; just use a search field and turn off the magnifying glass:
[[button cell] setSearchButtonCell:nil];
I was looking for the same thing for a multi-lined NSTextField the other day, with no luck so ended up using a button set with no border and to toggle with a small image. set very close to the NSTextField (not on it)
and:
- (IBAction)clearTextViewTex:(id)sender{
[textField performSelector:@selector(selectAll:)];
[textField performSelector:@selector(delete:)];
}
Doing it this way also retained the undo functions, without me having to write any NSUndoManager stuff.
精彩评论