Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CustomView.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
232 changes: 228 additions & 4 deletions CustomView/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion CustomView/Controllers/ProgressBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
}

89 changes: 81 additions & 8 deletions CustomView/Controllers/ProgressCircleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
22 changes: 18 additions & 4 deletions CustomView/Views/ProgressBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
62 changes: 57 additions & 5 deletions CustomView/Views/ProgressCircleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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) {
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
}