Reputation: 1363
We all know this will bring the color panel forwards: [[NSApplication sharedApplication] orderFrontColorPanel:nil];
, but how to hide it again? I tried orderOutColorPanel:
, but it does not work.
Upvotes: 1
Views: 425
Reputation: 1431
As of in 2016. There is a method. in Swift 3, you can toggle NSColorPanel like this:
func toggleColorPanel(_ sender: NSButton) {
if /*NSColorPanel.sharedColorPanelExists() &&*/ NSColorPanel.shared().isVisible {
NSColorPanel.shared().orderOut(self)
} else {
NSApplication.shared().orderFrontColorPanel(self)
}
}
Upvotes: 0
Reputation: 64002
When in doubt, use brute force:
- (void)hideColorPanel {
NSArray * wndws = [NSApp windows];
for( NSWindow * w in wndws ){
if( [w isKindOfClass:[NSColorPanel class]] ){
[w orderOut:nil];
break;
}
}
}
Upvotes: 2
Reputation: 2856
You are correct. There is no method on NSApplication to close the color panel. It is intended that the user will have control over the panel once it is shown.
Upvotes: 0