简体   繁体   English

优胜美地深色的NSPopover颜色反转

[英]NSPopover color invert in Yosemite dark color

I'm using NSPopover , and when I change the system dock color to dark (Yosemite new feature) some elements in my view invert their color. 我正在使用NSPopover ,当我将系统底座颜色更改为深色(Yosemite新功能)时,我视图中的某些元素会反转它们的颜色。

For example some labels changes from black to grey, or text fields background changes from white to black. 例如,某些标签从黑色变为灰色,或者文本字段背景从白色变为黑色。 And if I have a view with white background it is now changes to the blurred dark effect. 如果我有一个带白色背景的视图,它现在变为模糊的暗效果。

So two questions: 所以有两个问题:

  1. Can I cancel this behaviour and force the UI to act like in regular mode? 我可以取消此行为并强制用户界面像常规模式一样吗?

  2. Is there any rules here which element invert their color? 这里有哪些规则可以反转它们的颜色?

Because it seems that some element changes and some not. 因为似乎有些元素改变而有些则没有。

This is my app in Yosemite regular mode: 这是我在优胜美地常规模式中的应用:

在此输入图像描述

And this is in Yosemite dark mode: 这是在约塞米蒂黑暗模式:

在此输入图像描述

It might be a library you're using that's causing this behavior. 它可能是您正在使用的库导致此行为。 I just tested on a new project and I couldn't make the NSPopover black no matter how hard I tried. 我刚刚测试了一个新项目,无论我怎么努力,我都无法使NSPopover成为黑色。

What libraries are you using ? 你在用什么库? How did you set up your NSPopover ? 你是如何设置NSPopover的?

Maybe you could try changing the appearance property of the view ? 也许你可以尝试更改视图的外观属性?

view.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];

NSView has the property appearance because it conforms to NSAppearanceCustomization . NSView具有属性appearance因为它符合NSAppearanceCustomization

Also see NSAppearance . 另见NSAppearance

———————————————————————— ------------------------

Found the solution: 找到解决方案:

self.popover.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];

the result: 结果:

There are ways to do this, though I would recommend embracing it. 有办法做到这一点,但我建议接受它。 It's not concretely documented what will change and how. 它没有具体记录会发生什么变化以及如何变化。 But observation will show you what to do. 但观察会告诉你该怎么做。 Primarily it requires you do the opposite of opting in. Opting in is using Appkit interface elements as is as well as using the NSColor names provided as system colors and using the NSVisualEffectView. 主要是它需要你做与选择相反的操作。选择使用Appkit接口元素,以及使用作为系统颜色提供的NSColor名称并使用NSVisualEffectView。 That means to explicitly opt out you need to go around and basically customize views and that mostly means setting explicit colors and occasionally subclassing. 这意味着要明确选择退出,你需要绕过并基本上自定义视图,这主要意味着设置明确的颜色和偶尔子类化。 Out of the box HUD style popovers and panels would be opting in. 开箱即用的HUD风格的popovers和面板将选择加入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM