Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Created March 10, 2018 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagimaru/330c4bd5fc25d8705093b36a88b24735 to your computer and use it in GitHub Desktop.
Save usagimaru/330c4bd5fc25d8705093b36a88b24735 to your computer and use it in GitHub Desktop.
IBInspectable backgroundColor for NSView
import Cocoa
extension NSView {
@IBInspectable var backgroundColor: NSColor? {
get {
guard let layer = layer, let backgroundColor = layer.backgroundColor else {return nil}
return NSColor(cgColor: backgroundColor)
}
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