Skip to content

Instantly share code, notes, and snippets.

@Abhishek9634
Created March 30, 2019 17:36
Show Gist options
  • Save Abhishek9634/4751c8e2fd2c498aeae998ae3c8bc72c to your computer and use it in GitHub Desktop.
Save Abhishek9634/4751c8e2fd2c498aeae998ae3c8bc72c to your computer and use it in GitHub Desktop.
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