0

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.

Jay
  • 6,572
  • 3
  • 37
  • 65
PR Singh
  • 653
  • 5
  • 15

1 Answers1

0

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.

Sandeep
  • 20,908
  • 7
  • 66
  • 106
  • I want to detect only the last color? When i release the mouse on color well?? – PR Singh Mar 03 '14 at 17:53
  • 1
    So, the colorChanged: method is triggered everytime you change the color, you could then store the value in some property to know the last change. – Sandeep Mar 03 '14 at 17:56