NSTextField Clear Button

UITextFieldClearButtonMode can be installed on the iPhone to show a small clear button (X) at the end of text input. Similarly, on a Mac NSSearchFieldthere is a nice button on it at the end. My question is: is there a way to enable this under normal NSTextField?

+3
source share
2 answers

There is nothing built in; just use the search box and turn off the magnifying glass:

[[button cell] setSearchButtonCell:nil];
+6
source

I was looking for the same thing for multi-line NSTextField the other day, with no luck, so I ended up using a set of buttons without a border and switching with a small image. very close to NSTextField (not on it)

and

- (IBAction)clearTextViewTex:(id)sender{

 [textField performSelector:@selector(selectAll:)];
[textField performSelector:@selector(delete:)];     

}

Executing this method also retained undo functions, without having to write any NSUndoManager content.

+1
source

Source: https://habr.com/ru/post/1787057/


All Articles