Created
March 10, 2018 17:20
-
-
Save usagimaru/330c4bd5fc25d8705093b36a88b24735 to your computer and use it in GitHub Desktop.
IBInspectable backgroundColor for NSView
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
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