Created
October 31, 2016 06:21
-
-
Save Cee/4bbec4c7aa26e9c124730d707e60dca6 to your computer and use it in GitHub Desktop.
Add a background color to NSView
This file contains hidden or 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 = layer?.backgroundColor { | |
return NSColor(cgColor: colorRef) | |
} else { | |
return nil | |
} | |
} | |
set { | |
wantsLayer = true | |
layer?.backgroundColor = newValue?.cgColor | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment