Cocoa HUD 窗口:删除透明度?

发布于 2024-10-01 11:36:57 字数 252 浏览 0 评论 0原文

我有一个标准 NSPanel 设置为 HUD 样式。我想更改背景颜色,主要是因为我想要一个工具栏,但没有看到任何使标准 nstoolbar 在 HUD 上看起来不错的方法,也没有看到直接自定义工具栏背景的方法。

我知道创建完全自定义窗口的方法有多种,并在其他情况下使用这些方法。在这种情况下,我想要窗口提供的所有好处,但我只是不想要透明度。有趣的是,我可以更改背景颜色,但不能更改 Alpha。设置 alpha 值对窗口没有影响。

以前有人解决过这个问题吗?

I have a standard NSPanel set to HUD style. I want to change the background color, primarily because I want to have a toolbar and don't see any way of making either a standard nstoolbar look good on a HUD nor a way of customizing the background of a toolbar directly.

I am aware of the multitude of ways for creating a completely custom window, and use those in other circumstances. In this case, I want all of the good things that a window provides, but I just don't want transparency. Interestingly, I can change the background color, but not the alpha. Setting alpha values has no effect on the window.

Anyone solved this problem before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2024-10-08 11:36:57

将面板的内容视图(只需在面板内单击即可选择它,而不是标题栏)子类设置为 SGPanelView ,并使用您的 drawRect 方法的实现来创建 SGPanelView类:SGPanelView,NSView 的子类:

- drawRect:(NSRect)dirtyrect {
  [[NSColor blackColor] set];
  [NSBezierPath fillRect:[self bounds]];
}

应该可以工作。如果不起作用,请尝试将 bounds 更改为 frame


请参阅 http://developer .apple.com/library/mac/#documentation/cocoa/reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html 了解更多信息。

Set the panel's content-view's (just click inside the panel to select it, not the titlebar) subclass to SGPanelView and make that SGPanelView with this implementation of a drawRect method of your class: SGPanelView, a subclass of NSView:

- drawRect:(NSRect)dirtyrect {
  [[NSColor blackColor] set];
  [NSBezierPath fillRect:[self bounds]];
}

Should work. If not working, try changing bounds to frame.


See http://developer.apple.com/library/mac/#documentation/cocoa/reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文