Created
March 30, 2019 17:36
-
-
Save Abhishek9634/4751c8e2fd2c498aeae998ae3c8bc72c 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
import UIKit | |
@IBDesignable | |
class ProgressBar: UIView { | |
let progressView: UIView = UIView() | |
@IBInspectable var sliderColor: UIColor = .blue { | |
didSet { | |
self.sliderView.backgroundColor = self.sliderColor | |
} | |
} | |
@IBInspectable var sliderBGColor: UIColor = .lightGray { | |
didSet { | |
self.backgroundColor = self.sliderBGColor | |
} | |
} | |
@IBInspectable var minValue: CGFloat = 0.0 | |
@IBInspectable var maxValue: CGFloat = 100.0 | |
@IBInspectable var sliderValue: CGFloat = 0.0 | |
override func awakeFromNib() { | |
self.addSubview(self.progressView) | |
self.layer.cornerRadius = self.bounds.height / 2 | |
self.clipsToBounds = true | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
self.updateProgress() | |
} | |
func updateProgress() { | |
let sliderWidth = self.bounds.width * (self.sliderValue / self.maxValue) | |
self.sliderView.frame = CGRect(x: self.bounds.origin.x, | |
y: self.bounds.origin.y, | |
width: sliderWidth, | |
height: self.bounds.height) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment