问题描述
我正在为菜单栏应用程序使用NSPopover,看来它的默认aqua主题(以及浅色和深色)使用半透明的背景对其进行了绘制。
I'm using a NSPopover for my menubar application and it seems that its default aqua theme (and also light and dark) paints it with a semi-transparent background.
我想要一个不透明的背景。
I want an opaque background.
因此我进行了搜索,发现我可以像这样设置contentViewController的背景颜色:
So I searched SO and found I can set a background color for the contentViewController like so:
if let popoverView = popover.contentViewController?.view.superview {
popoverView.wantsLayer = true
popoverView.layer?.backgroundColor = NSColor.controlBackgroundColor.withAlphaComponent(1.0).cgColor
}
可以,但是其中的任何UI控件都可以该视图控制器将其背景绘制为透明,如下所示:
That works, but any UI controls within that view controller draw their backgrounds as transparent, as seen like so:
我尝试将UI控件嵌入NSBox中,但是我得到了
I've tried embedding the UI controls within a NSBox but I get the same transparent background paint.
有什么解决方案?
这是一个,该示例演示了我所看到的内容:
Here's a sample project that demonstrates what I'm seeing:
编辑:那里是类似的票,但海报希望透明的背景而不是不透明的。无论如何,没有一种解决方案可以解决我的问题。
There is similar SO ticket but the poster wanted a transparent background instead of opaque. In any case, none of the solutions solved my problem.
推荐答案
感谢Willeke,答案是将其添加到AppDelegate中.applicationDidFinishLaunching()
The answer, thanks to Willeke, is to add this within AppDelegate.applicationDidFinishLaunching()
popover.appearance = NSAppearance(named: .aqua)
这篇关于从非透明NSPopover的NSButton复选框中抽出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!