diff --git a/CustomView.xcodeproj/project.xcworkspace/xcuserdata/pedrogiulianofarina.xcuserdatad/UserInterfaceState.xcuserstate b/CustomView.xcodeproj/project.xcworkspace/xcuserdata/pedrogiulianofarina.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..87b3e88 Binary files /dev/null and b/CustomView.xcodeproj/project.xcworkspace/xcuserdata/pedrogiulianofarina.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcschemes/xcschememanagement.plist b/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..2a99e1a --- /dev/null +++ b/CustomView.xcodeproj/xcuserdata/pedrogiulianofarina.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + CustomView.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/CustomView/Base.lproj/Main.storyboard b/CustomView/Base.lproj/Main.storyboard index 4b8cb5b..f37ac66 100644 --- a/CustomView/Base.lproj/Main.storyboard +++ b/CustomView/Base.lproj/Main.storyboard @@ -55,7 +55,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -67,7 +133,7 @@ - + @@ -75,6 +141,7 @@ + @@ -197,6 +264,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -205,15 +404,47 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -263,6 +494,7 @@ + @@ -385,6 +617,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -400,6 +764,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CustomView/Controllers/ProgressBarViewController.swift b/CustomView/Controllers/ProgressBarViewController.swift index 7c56694..94fbd9b 100644 --- a/CustomView/Controllers/ProgressBarViewController.swift +++ b/CustomView/Controllers/ProgressBarViewController.swift @@ -40,5 +40,13 @@ class ProgressBarViewController: UITableViewController { @IBAction func targetChange(_ sender: Any) { self.progressBarView?.targetValue = CGFloat(self.targetSlider.value) } + + @IBAction func tapTargetOccur(_ sender:UITapGestureRecognizer){ + self.progressBarView?.targetColor = sender.view?.backgroundColor ?? .gray + } + + @IBAction func tapProgressOccur(_ sender:UITapGestureRecognizer){ + self.progressBarView?.progressColor = sender.view?.backgroundColor ?? .red + } } diff --git a/CustomView/Controllers/ProgressCircleViewController.swift b/CustomView/Controllers/ProgressCircleViewController.swift index 266ef60..b662ef7 100644 --- a/CustomView/Controllers/ProgressCircleViewController.swift +++ b/CustomView/Controllers/ProgressCircleViewController.swift @@ -9,8 +9,8 @@ import UIKit class ProgressCircleViewController: UITableViewController { - - @IBOutlet weak var progressCircleView: ProgressCircleView? + @IBOutlet var progressViews: [ProgressCircleView]! + @IBOutlet weak var widthSlider: UISlider! @IBOutlet weak var progressSlider: UISlider! @IBOutlet weak var targetSlider: UISlider! @@ -18,27 +18,70 @@ class ProgressCircleViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value) - self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value) - self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value) + setValues(width: CGFloat(self.widthSlider.value), progress: CGFloat(self.progressSlider.value), target: CGFloat(self.targetSlider.value)) } override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) - self.progressCircleView?.setNeedsDisplay() + for chart in progressViews{ + chart.setNeedsDisplay() + } } @IBAction func widthChange(_ sender: Any) { - self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value) + setValues(width: CGFloat(self.widthSlider.value)) } @IBAction func progessChange(_ sender: Any) { - self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value) + setValues(progress: CGFloat(self.progressSlider.value)) } @IBAction func targetChange(_ sender: Any) { - self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value) + setValues(target: CGFloat(self.targetSlider.value)) + } + + + + func setValues(width:CGFloat){ + setValues(width: width, progress: nil, target: nil) + } + + func setValues(progress:CGFloat){ + setValues(width: nil, progress: progress, target: nil) + } + + func setValues(target:CGFloat){ + setValues(width: nil, progress: nil, target: target) + } + func setValues(width:CGFloat?, progress:CGFloat?, target:CGFloat?){ + if let width = width{ + for chart in progressViews{ + chart.circleWidth = width + } + } + if let progress = progress{ + for chart in progressViews{ + chart.progressValue = progress + } + } + if let target = target{ + for chart in progressViews{ + chart.targetValue = target + } + } + } + + @IBAction func tapTargetOccur(_ sender : UITapGestureRecognizer){ + for chart in progressViews{ + chart.targetColor = sender.view?.backgroundColor ?? .gray + } + } + + @IBAction func tapProgressOccur(_ sender : UITapGestureRecognizer){ + for chart in progressViews{ + chart.progressColor = sender.view?.backgroundColor ?? .red + } } } diff --git a/CustomView/Views/ProgressBarView.swift b/CustomView/Views/ProgressBarView.swift index bfe9f6a..7935ec3 100644 --- a/CustomView/Views/ProgressBarView.swift +++ b/CustomView/Views/ProgressBarView.swift @@ -10,6 +10,27 @@ import UIKit @IBDesignable class ProgressBarView: UIView { + private var lblProgressPercentage:UILabel = UILabel(frame: CGRect(x: 15, y: 10, width: 60, height: 25)) + private var lblTargetPercentage:UILabel = UILabel(frame: CGRect(x: 15, y: 35, width: 60, height: 25)) + private func setPercentage(){ + lblTargetPercentage.text = "\(String(format:"%.1f", targetValue * 100))%" + lblProgressPercentage.text = "\(String(format:"%.1f", progressValue/targetValue * 100))%" + } + + @IBInspectable + var showPercentage:Bool = false{ + didSet{ + if showPercentage{ + addSubview(lblProgressPercentage) + addSubview(lblTargetPercentage) + } + else{ + lblProgressPercentage.removeFromSuperview() + lblTargetPercentage.removeFromSuperview() + } + } + } + @IBInspectable var lineWidth:CGFloat = 10.0 { didSet{ @@ -20,6 +41,7 @@ class ProgressBarView: UIView { @IBInspectable var targetValue:CGFloat = 0.25 { didSet{ + setPercentage() setNeedsDisplay() } } @@ -27,16 +49,31 @@ class ProgressBarView: UIView { @IBInspectable var progressValue:CGFloat = 0.0 { didSet{ + setPercentage() setNeedsDisplay() } } @IBInspectable - var lineColor:UIColor = UIColor.black + var lineColor:UIColor = UIColor.black{ + didSet{ + setNeedsDisplay() + } + } + @IBInspectable - var targetColor:UIColor = UIColor.blue + var targetColor:UIColor = UIColor.blue{ + didSet{ + setNeedsDisplay() + } + } + @IBInspectable - var progressColor:UIColor = UIColor.yellow + var progressColor:UIColor = UIColor.yellow{ + didSet{ + setNeedsDisplay() + } + } override func draw(_ rect: CGRect) { diff --git a/CustomView/Views/ProgressCircleView.swift b/CustomView/Views/ProgressCircleView.swift index 9eb1956..ed99a37 100644 --- a/CustomView/Views/ProgressCircleView.swift +++ b/CustomView/Views/ProgressCircleView.swift @@ -13,11 +13,33 @@ import UIKit @IBDesignable class ProgressCircleView: UIView { + private var lblProgressPercentage:UILabel = UILabel(frame: CGRect(x: 15, y: 10, width: 60, height: 25)) + private var lblTargetPercentage:UILabel = UILabel(frame: CGRect(x: 15, y: 35, width: 60, height: 25)) + private func setPercentage(){ + lblTargetPercentage.text = "\(String(format:"%.1f", targetValue * 100))%" + lblProgressPercentage.text = "\(String(format:"%.1f", progressValue/targetValue * 100))%" + } + + @IBInspectable + var showPercentage:Bool = false{ + didSet{ + if showPercentage{ + addSubview(lblProgressPercentage) + addSubview(lblTargetPercentage) + } + else{ + lblProgressPercentage.removeFromSuperview() + lblTargetPercentage.removeFromSuperview() + } + } + } + @IBInspectable // The value of current progress between 0.0 and 1.0 var progressValue:CGFloat = 0.0 { didSet{ + setPercentage() setNeedsDisplay() } } @@ -26,6 +48,7 @@ class ProgressCircleView: UIView { // TargetValue is a value between 0.0 and 1.0 that represent the value to be archieved var targetValue:CGFloat = 0.75 { didSet{ + setPercentage() setNeedsDisplay() } } @@ -38,13 +61,25 @@ class ProgressCircleView: UIView { } @IBInspectable - var circleColor:UIColor = UIColor.black + var circleColor:UIColor = UIColor.black{ + didSet{ + setNeedsDisplay() + } + } @IBInspectable - var progressColor:UIColor = UIColor.yellow + var progressColor:UIColor = UIColor.yellow{ + didSet{ + setNeedsDisplay() + } + } @IBInspectable - var targetColor:UIColor = UIColor.green + var targetColor:UIColor = UIColor.green{ + didSet{ + setNeedsDisplay() + } + } // Method that draw the circle, progress and target override func draw(_ rect: CGRect) {