Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the background color of the unified NSToolbar (in Yosemite)

Tags:

swift

cocoa

I want to have a unified toolbar and therefore I found this post:

How can I create Yosemite-style unified toolbar in Interface Builder?

self.window.titleVisibility = NSWindowTitleVisibility.Hidden

works perfect.

But is there a way to change the background color for the toolbar? I tried with self.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark), but this only brings a complete black toolbar (that's too dark). I want to have a custom color.

like image 908
Lupurus Avatar asked Mar 17 '23 05:03

Lupurus


1 Answers

This one works:

https://stackoverflow.com/a/28692893/2062613

  1. Set the window to textured in IB (I don't see a possibility to do it at runtime)

  2. Use this code:

    self.window.titleVisibility = NSWindowTitleVisibility.Hidden
    self.window.backgroundColor = NSColor.whiteColor()
    

UPDATE:

To prevent, that the toolbar becomes transparent in Yosemite (if you have a scrollview below the Toolbar), use this code:

self.window.appearance = NSAppearance(named: NSAppearanceNameAqua)
like image 84
Lupurus Avatar answered Apr 07 '23 00:04

Lupurus