将不透明度滑块添加到颜色面板中的一种颜色良好,但不添加其他颜色 [英] Add opacity slider to the color panel for one color well but not others

查看:77
本文介绍了将不透明度滑块添加到颜色面板中的一种颜色良好,但不添加其他颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向显示1种特定NSColorWell的NSColorPanel添加一个不透明度滑块。所有其他颜色的孔不应显示不透明度滑块。

I'd like to add a opacity slider to the NSColorPanel that is shown for 1 specific NSColorWell. All other color wells should not show the opacity slider.

我知道我可以像这样设置sharedColorPanel:

I know I can set this for the sharedColorPanel like so:

 [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];

但是当我只希望单一颜色的这种行为时该怎么办?

But how do I do this when I only want this behavior for a single color well?

我尝试添加IBAction,但是单击颜色很好时不会调用此IBAction。 (因此,在显示面板之前,我无法进行任何更改)。当您在颜色面板中选择另一种颜色时,就会调用它。

I tried adding an IBAction, but this IBAction is not called when you click the color well. (So I can't make any changes before the panel is displayed). It is called when you choose another color in the color panel.

推荐答案

确定,这是有效的代码。将IB中的colorwell类设置为AlphaColorWell:**

OK, here's the code that works. Set the colorwell class in IB to AlphaColorWell:**

@implementation AlphaColorWell

- (void)activate:(BOOL)exclusive
{
    [[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
    [super activate:exclusive];
}

- (void)deactivate
{
    [super deactivate];
    [[NSColorPanel sharedColorPanel] setShowsAlpha:NO];
}

@end

这篇关于将不透明度滑块添加到颜色面板中的一种颜色良好,但不添加其他颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆