Wes*_*ley 8 cocoa objective-c nscolorpanel nscolorwell
我想为NSColorPanel添加一个不透明度滑块,该滑块显示为1个特定的NSColorWell.所有其他颜色的孔不应显示不透明度滑块.
我知道我可以为sharedColorPanel设置这样:
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
Run Code Online (Sandbox Code Playgroud)
但是,当我只想要单一颜色的这种行为时,我该怎么做呢?
我尝试添加IBAction,但是当您单击颜色时不会调用此IBAction.(所以在显示面板之前我无法进行任何更改).在颜色面板中选择其他颜色时会调用它.
Wes*_*ley 12
好的,这是有效的代码.将IB中的colorwell类设置为AlphaColorWell:**
@implementation AlphaColorWell
- (void)activate:(BOOL)exclusive
{
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
[super activate:exclusive];
}
- (void)deactivate
{
[super deactivate];
[[NSColorPanel sharedColorPanel] setShowsAlpha:NO];
}
@end
Run Code Online (Sandbox Code Playgroud)
AppKit 没有在面板中显示不透明度滑块,因为它认为应用程序不支持 alpha,这是默认值。因此,而不是子类,只需这样做:
func applicationDidFinishLaunching(_ aNotification: Notification) {
...
NSColor.ignoresAlpha = false
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1200 次 |
| 最近记录: |