Skip to content

Instantly share code, notes, and snippets.

@DonMag
Created June 24, 2019 12:45
Show Gist options
  • Save DonMag/7c5eb9318f328b42d6b879f322f44ec9 to your computer and use it in GitHub Desktop.
Save DonMag/7c5eb9318f328b42d6b879f322f44ec9 to your computer and use it in GitHub Desktop.
class VerticalProgressViewController: UIViewController {
let theButton: UIButton = {
let v = UIButton()
v.translatesAutoresizingMaskIntoConstraints = false
v.setTitle("Tap Me", for: .normal)
v.setTitleColor(.red, for: .normal)
return v
}()
let vProgView: VerticalProgressView = {
let v = VerticalProgressView()
v.translatesAutoresizingMaskIntoConstraints = false
return v
}()
var p = Float(0.0)
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(theButton)
view.addSubview(vProgView)
NSLayoutConstraint.activate([
// add button 40-pts from top, centered vertically
theButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 40.0),
theButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
// add vertical progress view constrained 40-pts top, leading, bottom, and width 40
vProgView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 40.0),
vProgView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -40.0),
vProgView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 40.0),
vProgView.widthAnchor.constraint(equalToConstant: 40.0),
])
// initialize at 0.0
vProgView.setProgress(p, animated: false)
theButton.addTarget(self, action: #selector(didTap(_:)), for: .touchUpInside)
}
@objc func didTap(_ sender: Any) {
// increment the progress by 0.05 (5%) with each tap
p += 0.05
vProgView.setProgress(p, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment