NSPopover color invert in Yosemite dark color
Asked Answered
A

2

7

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.

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:

enter image description here

And this is in Yosemite dark mode:

enter image description here

Alva answered 1/10, 2014 at 18:30 Comment(0)
L
2

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. 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.

Litalitany answered 4/10, 2014 at 10:38 Comment(4)
Popovers might be limited in customization. If the user turns on Reduce Transparency in Accessibilty preferences you will see differences as well.Litalitany
when is this behaviour (color invert) happens? will it happen for some UI element in any window when going to dark mode? or only when in popover?Alva
Dark mode. There are NSNotification you can observe for that and accessibility changes. The new ones might only be noted in the AppKit release notes for 10.10 or in a header. I forget which header.Litalitany
Technically, there are also color changes that happen when a window changes to/from main or key status or when an app becomes/resigns active status. Just switch apps and you will notice these things happen. The combination in total means you might want lots of colors for various states (dark + active, dark + inactive, etc). The states are not documented directly and the ivars that AppKit uses to make views change are private. So you need to set up your own. Once you do this a few times you will start thinking about your own framework ;)Litalitany
H
10

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.

What libraries are you using ? How did you set up your 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.

Also see NSAppearance.

————————————————————————

Found the solution:

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

the result:

Hospitality answered 4/10, 2014 at 10:14 Comment(4)
I added a photo, as you can see, the element background becomes black.Alva
i added another image of my app without choosing Yosemite dark modeAlva
The drawback of this approach is that, the popover always looks bright even when system appearance is set to dark mode. There doesn't seem to be a way to have the popover matches system appearance (light or dark), and without that stupid transparency.Maybe
The question is about forcing the UI to use a specific color. Just because this answer doesn't pertain to your completely different issue (matching system color), that doesn't mean it has a "drawback". That said, to match the system color observe the AppleInterfaceThemeChangedNotification distributed notification, use NSAppearance.current().name to determine whether the system is set to Light/Dark, and change accordingly. To get rid of the transparency (again, different issue) #19979120Hospitality
L
2

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. 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.

Litalitany answered 4/10, 2014 at 10:38 Comment(4)
Popovers might be limited in customization. If the user turns on Reduce Transparency in Accessibilty preferences you will see differences as well.Litalitany
when is this behaviour (color invert) happens? will it happen for some UI element in any window when going to dark mode? or only when in popover?Alva
Dark mode. There are NSNotification you can observe for that and accessibility changes. The new ones might only be noted in the AppKit release notes for 10.10 or in a header. I forget which header.Litalitany
Technically, there are also color changes that happen when a window changes to/from main or key status or when an app becomes/resigns active status. Just switch apps and you will notice these things happen. The combination in total means you might want lots of colors for various states (dark + active, dark + inactive, etc). The states are not documented directly and the ivars that AppKit uses to make views change are private. So you need to set up your own. Once you do this a few times you will start thinking about your own framework ;)Litalitany

© 2022 - 2024 — McMap. All rights reserved.