Created
December 8, 2020 18:38
-
-
Save revblaze/0b572ce78999916028f423866ebb1dc5 to your computer and use it in GitHub Desktop.
Extension: Easily set NSView background color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSView { | |
var backgroundColor: NSColor? { | |
get { | |
if let colorRef = self.layer?.backgroundColor { | |
return NSColor(cgColor: colorRef) | |
} else { | |
return nil | |
} | |
} | |
set { | |
self.wantsLayer = true | |
self.layer?.backgroundColor = newValue?.cgColor | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage Example