我已经共享了 NSColorPanel 的实例,并将选择器设置为他。我将它用于背景颜色和字体颜色。当我想设置文本颜色时,一切正常,但是当我想设置背景颜色时,选择器被调用两次,并且背景颜色已更改为以前的颜色。有一些代码:
- (IBAction)showColorPanel:(id)sender {
NSColorPanel *panel = [NSColorPanel sharedColorPanel];
[panel orderFront:nil];
//[panel ]
[panel setAction:@selector(changeColorForBackground:)];
[panel setTarget:self];
[panel makeKeyAndOrderFront:self];
isFontPanel = NO;
[[self getDesktopController] setFirstString];
}
选择器:
- (void)changeColorForBackground:(id)sender {
if (!isFontPanel) {
DesktopController *desktopController = [self getDesktopController];
[desktopController updateCellBackgroundColor:[sender color]];
}
}
谢谢回复!