El Tomato
El Tomato

Reputation: 6707

Updating Custom NSWindow Appearance

enter image description here

As shown above, I have a view controller (NSViewController) and a window controller (NSWindowController). And I have a custom window (NSWindow) so that I can customize the look of the main window. Specially, I just want to set a particular color to its background color.

class BasicBorderlessWindow: NSWindow {
    override init(contentRect: NSRect, styleMask style: NSWindowStyleMask, backing bufferingType: NSBackingStoreType, defer flag: Bool) {
        super.init(contentRect: contentRect, styleMask: style, backing: .buffered, defer: false)
        self.isOpaque = false
        self.backgroundColor = NSColor.green
    }
}

Now, the entire window is green.

What I want to know is a way of changing the color of entire window once the application starts up. The subclassed window (BasicBorderlessWindow) is wired to the window controller. So I can access it from the view controller. I can create a function to set a new color so that I can call it from the view controller. But I cannot refresh the window. So how do I change window's background color and update it? Thanks.

Upvotes: 1

Views: 769

Answers (1)

SilverWolf
SilverWolf

Reputation: 304

Try setting the window's background color from within the window controller. You don't need an NSWindow subclass for this at all.

self.window?.backgroundColor = NSColor.blue

Upvotes: 1

Related Questions