Skip to content

Instantly share code, notes, and snippets.

@eonist
Last active January 23, 2017 15:05
Show Gist options
  • Save eonist/924209f6b54a5b415b7a59a4274d95a4 to your computer and use it in GitHub Desktop.
Save eonist/924209f6b54a5b415b7a59a4274d95a4 to your computer and use it in GitHub Desktop.
swift 3.0, NSButton, NSTextField (Experiment) (standalone window)
//forked from: https://github.com/BergQuester/Interactive-Window-Swift-Playground
import Cocoa
import XCPlayground
// Window size
let windowRect = NSRect(x: 30, y: 30, width: 300, height: 300)
var window = NSWindow(contentRect: NSRect(x: 30, y: 30, width: 300, height: 300), styleMask: NSWindowStyleMask.titled, backing: .buffered, defer: false)
// Configure window here
// Content view
let viewRect = NSRect(x: 0, y: 0, width: 200, height: 200)
var view:NSView = NSView(frame: viewRect)
// configure your content view and add subviews here
var textField = NSTextField(frame: NSRect(x: 30, y: 30, width: 100, height: 20))
textField.stringValue = "Test"
view.addSubview(textField)
var button = NSButton(frame: NSRect(x: 30, y: 60, width: 100, height: 30))
button.highlight(true)
var buttonCell:NSButtonCell = button.cell as! NSButtonCell
buttonCell.bezelStyle = NSBezelStyle.rounded
view.addSubview(button)
// display window
window.contentView = view
window.makeKeyAndOrderFront(nil)
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment