Skip to content

Instantly share code, notes, and snippets.

@DonMag
Last active February 27, 2018 14:11
Show Gist options
  • Select an option

  • Save DonMag/75ef8250a03305d695c353ce15e32f08 to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/75ef8250a03305d695c353ce15e32f08 to your computer and use it in GitHub Desktop.
import UIKit
import PlaygroundSupport
class TestViewController : UIViewController {
let btn: UIButton = {
let b = UIButton()
b.translatesAutoresizingMaskIntoConstraints = false
b.setTitle("Tap Me", for: .normal)
b.backgroundColor = .red
return b
}()
let theProgressView: UIProgressView = {
let v = UIProgressView()
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(btn)
btn.addTarget(self, action: #selector(didTap(_:)), for: .touchUpInside)
btn.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
btn.topAnchor.constraint(equalTo: view.topAnchor, constant: 20.0).isActive = true
view.addSubview(theProgressView)
theProgressView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
theProgressView.topAnchor.constraint(equalTo: btn.bottomAnchor, constant: 40.0).isActive = true
theProgressView.widthAnchor.constraint(equalToConstant: 100.0).isActive = true
theProgressView.progress = 0.0
}
@objc func didTap(_ sender: Any?) -> Void {
theProgressView.progress += 0.01
DispatchQueue.main.async {
print(self.theProgressView.progress)
for v in self.theProgressView.subviews {
print(v)
}
}
}
}
let vc = TestViewController()
vc.view.backgroundColor = .white
PlaygroundPage.current.liveView = vc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment