What is the correct way to use the Vibrant Dark (NSAppearanceNameVibrantDark
) or Vibrant Light (NSAppearanceNameVibrantLight
) modes with an NSWindow
?
I'm building an application and would like to offer the new Vibrant Dark appearance as an option for the main application's NSWindow
. The window itself is a pretty straight forward window with an NSToolbar
across the top and a scroll view as the main content area.
There's plenty of information from Apple on using the new vibrancy appearances in conjunction with an NSVisualEffectsView
, but I'm looking for clarification on how to use those appearances on an NSWindow
.
In the NSAppearance.h
header file, there's a comment that states that the vibrant appearances should only be set on an NSVisualEffectsView
. There's no mention of it being supported on NSWindow
.
The WWDC videos talk about making sure that you're using layer-backed views and that you're allowing vibrancy on your subviews when using the new vibrant appearances, but again, no mention of using them on an NSWindow
.
The VisualEffectsPlayground sample code does have an example of a Facetime-like application that uses the dark vibrancy mode, but it doesn't have a toolbar and it uses the full-content mask.
From that information, I'm doing the following in my NSWindowController's windowDidLoad
method:
[self.window.contentView setWantsLayer:YES];
self.window.appearance = [NSAppearance appearanceNamed:NSAppearanceNameVibrantDark];
And, sure enough, I get a black NSToolbar
with a black window title bar. So it looks like it's working properly, but when my scrollview scrolls its content (thumbnails of images) the standard translucency under the NSToolbar
and the window's title bar is either not present or is randomly present. There doesn't seem to be any pattern. Sometimes when I scroll the scrollview, the content is shown in the "blurred" state under the toolbar and title bar. Other times when I scroll, the toolbar and titlebar are just an opaque black. (The title bar and toolbar still draw their titles and buttons.)
When I don't request a layer for the window's content view, then I get more a gray titlebar and window title rather than a "pure" black one. (My scrollview's background color can be either white, dark gray or black.)
Any help or clarification on how to properly configure an NSWindow
(that contains an NSToolbar
and an NSScollView
) to use the new vibrancy appearances would be much appreciated.
This will make a dark mode window. Subsequently, everything in the window (including titlebar, toolbar and even dialogue sheets) will become dark.
let USE_DARK_MODE = true
if USE_DARK_MODE {
window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
window.invalidateShadow()
}
invalidateShadow
doesn't seem required, but sometimes shadow does not work properly if lacked. (OS X 10.10)
I figured that you can subclass NSWindowController
. Set the class for your Window Controller in IB to your custom NSWindowController
. After that in the windowDidLoad function
self.window?.titlebarAppearsTransparent = true
Also set "Full Size Content View" in the Attribute inspector for the NSWindow
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With