Created
September 29, 2019 20:46
-
-
Save hungtruong/c5963ec63481f39877e562da3c93a13a to your computer and use it in GitHub Desktop.
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
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