diff --git a/CustomView.xcodeproj/project.xcworkspace/xcuserdata/paulaleite.xcuserdatad/UserInterfaceState.xcuserstate b/CustomView.xcodeproj/project.xcworkspace/xcuserdata/paulaleite.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..ab4da0a
Binary files /dev/null and b/CustomView.xcodeproj/project.xcworkspace/xcuserdata/paulaleite.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/CustomView.xcodeproj/xcuserdata/paulaleite.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/CustomView.xcodeproj/xcuserdata/paulaleite.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
new file mode 100644
index 0000000..fe2b454
--- /dev/null
+++ b/CustomView.xcodeproj/xcuserdata/paulaleite.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -0,0 +1,5 @@
+
+
+
diff --git a/CustomView.xcodeproj/xcuserdata/paulaleite.xcuserdatad/xcschemes/xcschememanagement.plist b/CustomView.xcodeproj/xcuserdata/paulaleite.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..2a99e1a
--- /dev/null
+++ b/CustomView.xcodeproj/xcuserdata/paulaleite.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..f6c1abd 100644
--- a/CustomView/Base.lproj/Main.storyboard
+++ b/CustomView/Base.lproj/Main.storyboard
@@ -77,12 +77,68 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -132,7 +188,7 @@
-
+
@@ -197,6 +253,104 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,15 +359,17 @@
-
+
+
+
-
+
@@ -385,6 +541,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -401,7 +625,7 @@
-
+
diff --git a/CustomView/Controllers/ProgressBarViewController.swift b/CustomView/Controllers/ProgressBarViewController.swift
index 7c56694..9d0ee58 100644
--- a/CustomView/Controllers/ProgressBarViewController.swift
+++ b/CustomView/Controllers/ProgressBarViewController.swift
@@ -40,5 +40,24 @@ class ProgressBarViewController: UITableViewController {
@IBAction func targetChange(_ sender: Any) {
self.progressBarView?.targetValue = CGFloat(self.targetSlider.value)
}
+
+ @IBAction func colorButtonPressed(_ sender: UIButton) {
+ let color = UIColor.random
+ sender.backgroundColor = color
+
+ switch sender.tag {
+ case 0:
+ progressBarView?.lineColor = color
+ self.widthSlider.tintColor = color
+ case 1:
+ progressBarView?.progressColor = color
+ self.progressSlider.tintColor = color
+ case 2:
+ progressBarView?.targetColor = color
+ self.targetSlider.tintColor = color
+ default:
+ break
+ }
+
+ }
}
-
diff --git a/CustomView/Controllers/ProgressCircleViewController.swift b/CustomView/Controllers/ProgressCircleViewController.swift
index 266ef60..5ccf1f7 100644
--- a/CustomView/Controllers/ProgressCircleViewController.swift
+++ b/CustomView/Controllers/ProgressCircleViewController.swift
@@ -10,35 +10,108 @@ import UIKit
class ProgressCircleViewController: UITableViewController {
- @IBOutlet weak var progressCircleView: ProgressCircleView?
+ @IBOutlet weak var biggestProgressCircleView: ProgressCircleView?
@IBOutlet weak var widthSlider: UISlider!
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!
+ @IBOutlet weak var mediumProgressCircleView: ProgressCircleView!
+ @IBOutlet weak var smallerProgressCircleView: ProgressCircleView!
+
+
+
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)
+ self.biggestProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.biggestProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.biggestProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+
+ self.mediumProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.mediumProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.mediumProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+
+ self.smallerProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.smallerProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.smallerProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
- self.progressCircleView?.setNeedsDisplay()
+ self.biggestProgressCircleView?.setNeedsDisplay()
+ self.mediumProgressCircleView?.setNeedsDisplay()
+ self.smallerProgressCircleView?.setNeedsDisplay()
}
@IBAction func widthChange(_ sender: Any) {
- self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.biggestProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.mediumProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
+ self.smallerProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
}
@IBAction func progessChange(_ sender: Any) {
- self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.biggestProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.mediumProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
+ self.smallerProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
}
@IBAction func targetChange(_ sender: Any) {
- self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+ self.biggestProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+ self.mediumProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+ self.smallerProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
+ }
+
+ @IBAction func colorButtonPressed(_ sender: UIButton) {
+ let color = UIColor.random
+ sender.backgroundColor = color
+
+ switch sender.tag {
+ case 0:
+ biggestProgressCircleView?.circleColor = color
+ mediumProgressCircleView?.circleColor = color
+ smallerProgressCircleView?.circleColor = color
+ self.widthSlider.tintColor = color
+ case 1:
+ biggestProgressCircleView?.progressColor = color
+ mediumProgressCircleView?.progressColor = color
+ smallerProgressCircleView?.progressColor = color
+ self.progressSlider.tintColor = color
+ case 2:
+ biggestProgressCircleView?.targetColor = color
+ mediumProgressCircleView?.targetColor = color
+ smallerProgressCircleView?.targetColor = color
+ self.targetSlider.tintColor = color
+ default:
+ break
+ }
+
+ }
+
+ @IBAction func typeOfChallengeChanged(_ sender: UISegmentedControl) {
+
+ switch sender.selectedSegmentIndex {
+ case 0:
+ biggestProgressCircleView?.hideLabel()
+ mediumProgressCircleView.hideLabel()
+ smallerProgressCircleView.hideLabel()
+ biggestProgressCircleView?.isHidden = false
+ mediumProgressCircleView.isHidden = false
+ smallerProgressCircleView.isHidden = false
+ default:
+ biggestProgressCircleView?.showLabel()
+ mediumProgressCircleView.showLabel()
+ smallerProgressCircleView.showLabel()
+ mediumProgressCircleView.isHidden = true
+ smallerProgressCircleView.isHidden = true
+
+ }
}
}
+extension UIColor {
+ static var random: UIColor {
+ return UIColor(red: .random(in: 0...1), green: .random(in: 0...1), blue: .random(in: 0...1), alpha: 1.0)
+ }
+}
diff --git a/CustomView/Views/ProgressBarView.swift b/CustomView/Views/ProgressBarView.swift
index bfe9f6a..45e90c6 100644
--- a/CustomView/Views/ProgressBarView.swift
+++ b/CustomView/Views/ProgressBarView.swift
@@ -32,16 +32,30 @@ class ProgressBarView: UIView {
}
@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) {
- //Important constants for circle
+ //Important constants for line
let start:CGPoint = CGPoint(x: rect.minX + lineWidth, y: rect.midY)
let end:CGPoint = CGPoint(x: rect.maxX - lineWidth, y: rect.midY)
diff --git a/CustomView/Views/ProgressCircleView.swift b/CustomView/Views/ProgressCircleView.swift
index 9eb1956..e43013c 100644
--- a/CustomView/Views/ProgressCircleView.swift
+++ b/CustomView/Views/ProgressCircleView.swift
@@ -11,22 +11,26 @@
import UIKit
+// Consigo ver o meu desenho na storyboard enquanto uso
@IBDesignable
class ProgressCircleView: UIView {
+ // Aparecem os atributos no inspector
@IBInspectable
// The value of current progress between 0.0 and 1.0
var progressValue:CGFloat = 0.0 {
- didSet{
+ didSet {
setNeedsDisplay()
+ progressLabel?.text = String(format: "Progress: %.2f%%", progressValue * 100)
}
}
@IBInspectable
// TargetValue is a value between 0.0 and 1.0 that represent the value to be archieved
var targetValue:CGFloat = 0.75 {
- didSet{
+ didSet {
setNeedsDisplay()
+ targetLabel?.text = String(format: "Target: %.2f%%", targetValue * 100)
}
}
@@ -38,13 +42,49 @@ 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()
+ }
+ }
+
+ var targetLabel: UILabel!
+ var progressLabel: UILabel!
+
+ override func awakeFromNib() {
+ super.awakeFromNib()
+
+ targetLabel = UILabel()
+ targetLabel.font = UIFont(name: "Helvetica Neue", size: 12)
+ targetLabel.frame.size = CGSize(width: 110, height: 80)
+ targetLabel.textAlignment = .center
+ targetLabel.center = CGPoint(x: self.center.x, y: self.center.y - 20)
+ targetLabel.isHidden = true
+
+ progressLabel = UILabel()
+ progressLabel.font = UIFont(name: "Helvetica Neue", size: 12)
+ progressLabel.frame.size = CGSize(width: 110, height: 80)
+ progressLabel.textAlignment = .center
+ progressLabel.center = CGPoint(x: self.center.x, y: self.center.y)
+ progressLabel.isHidden = true
+
+ self.addSubview(targetLabel)
+ self.addSubview(progressLabel)
+ }
// Method that draw the circle, progress and target
override func draw(_ rect: CGRect) {
@@ -67,6 +107,7 @@ class ProgressCircleView: UIView {
// Sets the radius by the smallest side of the view
var radius:CGFloat = 0.0
+ // O raio vai ser o menor entre a altura e o
if rect.width < rect.height{
radius = (rect.width - circleWidth) / 2.0
}else{
@@ -94,5 +135,16 @@ class ProgressCircleView: UIView {
context?.setStrokeColor(progressColor.cgColor)
context?.addArc(center: centerPoint, radius: radius, startAngle: start, endAngle: progressEnd, clockwise: false)
context?.strokePath()
+
+ }
+
+ func hideLabel() {
+ targetLabel.isHidden = true
+ progressLabel.isHidden = true
+ }
+
+ func showLabel() {
+ targetLabel.isHidden = false
+ progressLabel.isHidden = false
}
}