문제

When you add an NSColorWell control, and click it, it displays the shared instance of NSColorPanel. Unfortunately, by default it does not show the alpha / opacity slider. This is also true when it is invoked from the default MainMenu > Format > Font > Show Colors

도움이 되었습니까?

해결책

Simply call the following line at any time in your app.

[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];

You can call it once in applicationDidFinishLaunching: or you can easily tie it to a switch like an NSButton checkbox with a simple IBAction method like this:

- (IBAction)showAlphaSliderInColorPanel:(id)sender {
    if ([sender state] == NSOnState) {
        [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
    } else {
        [[NSColorPanel sharedColorPanel] setShowsAlpha:NO];
    }
}

Just connect that to the Sent Actions selector item in the Connections Inspector with for a button configured to have an on / off state.

The change will occur live as you click.

A great example of how awesome Cocoa is when you want it to be.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top