Skip to content

Instantly share code, notes, and snippets.

@bhakes
Last active January 3, 2020 15:31
Show Gist options
  • Save bhakes/c69c1bae9f6ad7aaa78d42dc32478daa to your computer and use it in GitHub Desktop.
Save bhakes/c69c1bae9f6ad7aaa78d42dc32478daa to your computer and use it in GitHub Desktop.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
var button: UIButton?
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let button = UIButton()
button.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
button.setTitle("Hello, World!", for: .normal)
button.setTitleColor(.blue, for: .normal)
button.setTitleColor(.red, for: .highlighted)
button.layer.borderColor = UIColor.systemGreen.cgColor
button.layer.borderWidth = 1.5
button.addTarget(self, action: #selector(buttonTouchDown), for: .touchDown)
button.addTarget(self, action: #selector(buttonTouchUpInside), for: .touchUpInside)
self.button = button
view.addSubview(button)
self.view = view
}
@objc func buttonTouchDown() {
self.button?.layer.borderColor = UIColor.systemRed.cgColor
}
@objc func buttonTouchUpInside() {
self.button?.layer.borderColor = UIColor.systemGreen.cgColor
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment