HUD NSPanel 不太透明
我一直在网上搜索,但没有遇到更改HUD透明度(所有面板透明度,包括标题栏)的方法。可以改变吗?
谢谢
I've been searching for the web but I have not encountered the way to change the HUD's transparency (ALL the panel transparency, including title bar). It's possible to change it?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该能够使用从 NSWindow 继承的
setAlphaValue
:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html
You should be able to use the
setAlphaValue
, inherited from NSWindow:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html
这是不可能的。 HUD 面板设计为透明;他们不会让你改变他们的不透明度或他们的基本视图的不透明度。
您必须:1)在其中放置一个自定义的不透明子视图并使用半透明的标题栏; b) 使用具有常规样式的 NSPanel,您可以更改其背景颜色和不透明度,并接受它作为常规标题栏;或 d) 创建您自己的自定义窗口(该文章底部另一篇文章的良好链接)。另请参阅这篇关于制作您自己的文章 窗口框架(警告:该框架使用私有 API,并且已有几年历史)。
It's not possible. HUD panels are intended to be transparent; they won't let you change their opacity or the opacity of their base views.
You'll have to: 1) put a custom opaque subview in there and live with a translucent title bar; b) use an
NSPanel
with the regular style, whose background color and opacity you can change, and live with it being a regular title bar; or d) create your very own custom window (good link to another writeup at the bottom of that article). See also this article about making your own window frame (warning: that one uses private API, and is a few years old).这是可能的。您只需要通过在面板视图的核心动画层上设置颜色(包括 Alpha)以编程方式完成此操作。以下是设置透明度稍低的 HUD 面板的示例:
请记住,您必须在视图加载后执行此操作,例如。不要在 init 中设置它:
It is possible. You just need to do it programmatically by setting the color (including alpha) on the Core Animation layer of the panel's view. Here is an example of setting the HUD panel with slightly less transparency:
Just remember that you have to do this after the view has loaded, eg. don't set it in init: