2

In mac os 10.14 Apple have introduced new feature for user interface: Ligth and Dark themes. There are defined constants for some colors "UI Element Colors" from the NSColor class used for text/labels/content/buttons/etc colorising, but seems that there are no constant for NSView background.

Where to find default background color for NSView (for Light and Dark themes)?

slavik
  • 1,341
  • 2
  • 11
  • 16
  • The list you linked to has `ControlBackgroundColor`, `WindowBackgroundColor`, and `UnderPageBackgroundColor`. Are any of those what you're looking for? – Ian MacDonald Sep 27 '18 at 14:29
  • Ian MacDonald, unfortunatelly all of three constants that you mentioned are differs from default NSView color in DarkTheme – slavik Sep 27 '18 at 14:35
  • 2
    As far as I understand the NSView does not have a standard background color unlike a window or control. To set a background color you have to subclass the NSView and override the draw function to draw any background color you like. You would have had to choose your own color before 10.14 and now you'd also have to do that but switch the color according to light or dark mode. One answer how to do that is described here: https://stackoverflow.com/a/52406553/1912421 – Enie Oct 01 '18 at 09:57
  • Enie, when creating new macos cocoa application in xcode and adding an empty NSView you will see that it will be filled with some color (and that color will be changed if macOS theme will be changed). Where to find that filling color? – slavik Oct 01 '18 at 15:38
  • 1
    @Enie is right; `NSView` has no background color. When you create one in Xcode, the visual representation of it has a background, sure, but that's just Xcode making it visible so you can drag it around. When you actually build and run the app, you'll see that no drawing takes place. – zpasternack Dec 17 '19 at 05:04
  • @zpasternack - yes, you are right! default implementation of NSView draw nothing. I misunderstood owner of the color which we see on new application. So, in fact, I was asking about default NSWindow background color - is there any constant for it (WindowBackgroundColor is not the same)? – slavik Dec 18 '19 at 08:01

1 Answers1

0

What about NSColor.controlbackgroundcolor?

Alvaro Rivoir
  • 401
  • 3
  • 9