Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 295
JoeR Avatar asked Jan 22 '11 00:01

JoeR


2 Answers

There's nothing built-in; just use a search field and turn off the magnifying glass:

[[button cell] setSearchButtonCell:nil];
like image 143
Mike Abdullah Avatar answered Oct 07 '22 11:10

Mike Abdullah


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.

like image 31
markhunte Avatar answered Oct 07 '22 10:10

markhunte