Skip to content

Instantly share code, notes, and snippets.

@hungtruong
Created September 29, 2019 20:46
Show Gist options
  • Save hungtruong/c5963ec63481f39877e562da3c93a13a to your computer and use it in GitHub Desktop.
Save hungtruong/c5963ec63481f39877e562da3c93a13a to your computer and use it in GitHub Desktop.
func updateProgress(_ progress: Float) {
if self.progressView == nil {
let progressView = UIView()
progressView.backgroundColor = .black
progressView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(progressView)
let trailingConstraint =
progressView.leadingAnchor.constraint(equalTo: self.leadingAnchor)
NSLayoutConstraint.activate([
progressView.topAnchor.constraint(equalTo: self.topAnchor),
progressView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
progressView.widthAnchor.constraint(equalToConstant: 1.0),
trailingConstraint
])
self.progressView = progressView
self.progressViewTrailingConstraint = trailingConstraint
} else if let trailingConstraint = self.progressViewTrailingConstraint {
let offset = self.bounds.width * CGFloat(progress)
trailingConstraint.constant = offset
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment