Skip to content

Instantly share code, notes, and snippets.

@SteveTrewick
Created September 24, 2015 14:09
Show Gist options
  • Save SteveTrewick/13db3064ef9ad623ff5a to your computer and use it in GitHub Desktop.
Save SteveTrewick/13db3064ef9ad623ff5a to your computer and use it in GitHub Desktop.
Using NSColorPanerl with Swift on OS X
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
func applicationDidFinishLaunching(aNotification: NSNotification) {
let cp = NSColorPanel.sharedColorPanel()
cp.setTarget(self)
cp.setAction(Selector("colorDidChange:"))
cp.makeKeyAndOrderFront(self)
cp.continuous = true
}
func applicationWillTerminate(aNotification: NSNotification) {
}
func colorDidChange(sender:AnyObject) {
if let cp = sender as? NSColorPanel {
print(cp.color)
self.window.backgroundColor = cp.color
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment