How to detect last NSColorWell color selected in cocoa

947 views Asked by At

Is there any way to detect last NSColorWell color selected?

So far i have create NSColorWell with action and target programmatically, So how many time i changed the color that method is called that much time. So i want to identified last selected color of NSColorWell.

1

There are 1 answers

2
Sandeep On

NSColorPanelResponderMethod category (informal protocol) on NSObject implements a method called changeColor:. So, you could override this method inside your class to detect the color changes for NSColorWell.

@interface MyClass:NSObject 
 @property(nonatomic, strong) NSColor *lastColor;
@end

@implementation MyClass
  - (void)colorChanged:(id)sender{
    NSLog(@"Last color %@", lastColor);
    NSColor *newColor = [sender color];
    NSLog(@"NSColorWell changed color %@", [sender color]);
  }
@end

If you want to be able to keep track of the last font, then you would create a property and everytime the font changes, assign the new font to the property. This way you will be able to keep track of the last font.