Skip to content

Instantly share code, notes, and snippets.

@Cee
Created October 31, 2016 06:21
Show Gist options
  • Save Cee/4bbec4c7aa26e9c124730d707e60dca6 to your computer and use it in GitHub Desktop.
Save Cee/4bbec4c7aa26e9c124730d707e60dca6 to your computer and use it in GitHub Desktop.
Add a background color to NSView
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