-
-
Save eonist/75b752a5abcd472e6781d6a0c12f6919 to your computer and use it in GitHub Desktop.
InteractivePlayground with button that prints hello (swift 3.0.1)
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 AppKit | |
import XCPlayground | |
import Cocoa | |
import PlaygroundSupport | |
extension NSLayoutConstraint { | |
convenience init(view item: NSView, to toItem: NSView, attribute: NSLayoutAttribute, constant c: CGFloat = 0) { | |
self.init(item: item, attribute: attribute, | |
relatedBy: .equal, | |
toItem: toItem, attribute: attribute, | |
multiplier: 1.0, constant: c) | |
self.isActive = true | |
self.shouldBeArchived = true | |
item.translatesAutoresizingMaskIntoConstraints = false | |
} | |
} | |
let viewRect = NSRect(x: 0, y: 0, width: 300, height: 200) | |
var view = NSView(frame: viewRect) | |
view.wantsLayer = true | |
class Test: NSObject { | |
@objc func test(sender: AnyObject) { | |
Swift.print("Hallo") | |
} | |
} | |
let t = Test() | |
var button: NSButton = { | |
$0.title = "Hallo" | |
$0.target = t | |
$0.action = #selector(t.test) | |
$0.isEnabled = true | |
$0.bezelStyle = .rounded | |
return $0 | |
}(NSButton(frame: NSRect(x: 0, y: 0, width: 100, height: 30))) | |
view.addSubview(button) | |
PlaygroundPage.current.liveView = view | |
//PlaygroundPage.current.needsIndefiniteExecution = true | |
NSLayoutConstraint(view: button, to: view, attribute: .centerX) | |
NSLayoutConstraint(view: button, to: view, attribute: .centerY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment