Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect a color change in NSColorPanel

I have some code that opens a NSColorPanel. How would I be able to detect when the color is changed and then run a callback?

NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];
[colorPanel orderFront:nil];

Thanks in advance.

like image 759
consindo Avatar asked Jan 10 '12 08:01

consindo


2 Answers

You should use target action:

NSColorPanel *cp = [NSColorPanel sharedColorPanel];
[cp setTarget:self];
[cp setAction:@selector(colorUpdate:)];

and define the action this way:

-(void)colorUpdate:(NSColorPanel*)colorPanel{ 
    NSColor* theColor = colorPanel.color;
    ....your code

}
like image 166
MatterGoal Avatar answered Oct 21 '22 17:10

MatterGoal


There is a method - (void)changeColor:(id)sender. It sends to the first responder when the user selects a color in an NSColorPanel object. You can override this method in any responder that needs to respond to a color change. May be, it can help.

like image 42
Suvo08 K Avatar answered Oct 21 '22 17:10

Suvo08 K