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.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With