简体   繁体   中英

How to detect last NSColorWell color selected in cocoa

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM