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
12 changes: 12 additions & 0 deletions CustomView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
92949A602295DBF8008EE240 /* ProgressCircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92949A5F2295DBF8008EE240 /* ProgressCircleView.swift */; };
92949A622295E067008EE240 /* ProgressBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92949A612295E067008EE240 /* ProgressBarView.swift */; };
92FB2169229A55C5000AF93E /* ProgressBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 92FB2168229A55C5000AF93E /* ProgressBarViewController.swift */; };
B69A63E7229DB608004A1EF1 /* UIColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = B69A63E6229DB608004A1EF1 /* UIColorExtension.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -28,6 +29,7 @@
92949A5F2295DBF8008EE240 /* ProgressCircleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressCircleView.swift; sourceTree = "<group>"; };
92949A612295E067008EE240 /* ProgressBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarView.swift; sourceTree = "<group>"; };
92FB2168229A55C5000AF93E /* ProgressBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgressBarViewController.swift; sourceTree = "<group>"; };
B69A63E6229DB608004A1EF1 /* UIColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIColorExtension.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -69,6 +71,7 @@
92949A4B2295DAF3008EE240 /* CustomView */ = {
isa = PBXGroup;
children = (
B69A63E5229DB5EF004A1EF1 /* Extensions */,
9270CB38229A5DBA000A31AB /* Controllers */,
92949A5E2295DB10008EE240 /* Views */,
92949A4C2295DAF3008EE240 /* AppDelegate.swift */,
Expand All @@ -89,6 +92,14 @@
path = Views;
sourceTree = "<group>";
};
B69A63E5229DB5EF004A1EF1 /* Extensions */ = {
isa = PBXGroup;
children = (
B69A63E6229DB608004A1EF1 /* UIColorExtension.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -165,6 +176,7 @@
92FB2169229A55C5000AF93E /* ProgressBarViewController.swift in Sources */,
92949A602295DBF8008EE240 /* ProgressCircleView.swift in Sources */,
92949A4D2295DAF3008EE240 /* AppDelegate.swift in Sources */,
B69A63E7229DB608004A1EF1 /* UIColorExtension.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?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/>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>EnabledFullIndexStoreVisibility</key>
<false/>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>
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>
252 changes: 247 additions & 5 deletions CustomView/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions 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 colorChange(_ button: UIButton) {
let color = UIColor.random
button.backgroundColor = color

switch button.tag {
case 0:
self.progressBarView?.lineColor = color
self.widthSlider.tintColor = color
case 1:
self.progressBarView?.progressColor = color
self.progressSlider.tintColor = color
case 2:
self.progressBarView?.targetColor = color
self.targetSlider.tintColor = color
default:
break
}
}
}

82 changes: 73 additions & 9 deletions CustomView/Controllers/ProgressCircleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,99 @@ import UIKit

class ProgressCircleViewController: UITableViewController {

@IBOutlet weak var progressCircleView: ProgressCircleView?
@IBOutlet weak var largestProgressCircleView: ProgressCircleView?
@IBOutlet weak var mediumProgressCircleView: ProgressCircleView?
@IBOutlet weak var smallerProgressCircleView: ProgressCircleView?
@IBOutlet weak var widthSlider: UISlider!
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!

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.largestProgressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
self.largestProgressCircleView?.progressValue = CGFloat(self.progressSlider.value)
self.largestProgressCircleView?.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.largestProgressCircleView?.setNeedsDisplay()
self.mediumProgressCircleView?.setNeedsDisplay()
self.smallerProgressCircleView?.setNeedsDisplay()
}

@IBAction func widthChange(_ sender: Any) {
self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
self.largestProgressCircleView?.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.largestProgressCircleView?.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.largestProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
self.mediumProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
self.smallerProgressCircleView?.targetValue = CGFloat(self.targetSlider.value)
}

@IBAction func colorChange(_ button: UIButton) {
let color = UIColor.random
button.backgroundColor = color

switch button.tag {
case 0:
self.largestProgressCircleView?.circleColor = color
self.mediumProgressCircleView?.circleColor = color
self.smallerProgressCircleView?.circleColor = color
self.widthSlider.tintColor = color
case 1:
self.largestProgressCircleView?.progressColor = color
self.mediumProgressCircleView?.progressColor = color
self.smallerProgressCircleView?.progressColor = color
self.progressSlider.tintColor = color
case 2:
self.largestProgressCircleView?.targetColor = color
self.mediumProgressCircleView?.targetColor = color
self.smallerProgressCircleView?.targetColor = color
self.targetSlider.tintColor = color
default:
break
}
}

@IBAction func challengeChanged(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
sender.tintColor = #colorLiteral(red: 0.5787474513, green: 0.3215198815, blue: 0, alpha: 1)
mediumProgressCircleView?.isHidden = false
smallerProgressCircleView?.isHidden = false

largestProgressCircleView?.hideLabels()
mediumProgressCircleView?.hideLabels()
smallerProgressCircleView?.hideLabels()
default:
sender.tintColor = #colorLiteral(red: 0.6642242074, green: 0.6642400622, blue: 0.6642315388, alpha: 1)
mediumProgressCircleView?.isHidden = true
smallerProgressCircleView?.isHidden = true

largestProgressCircleView?.showLabels()
mediumProgressCircleView?.showLabels()
smallerProgressCircleView?.showLabels()
}
}

}

15 changes: 15 additions & 0 deletions CustomView/Extensions/UIColorExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UIColorExtension.swift
// CustomView
//
// Created by Lucas Fernandez Nicolau on 28/05/19.
// Copyright © 2019 Joaquim Pessoa Filho. All rights reserved.
//

import UIKit

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)
}
}
23 changes: 20 additions & 3 deletions CustomView/Views/ProgressBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,29 @@ 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 prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}

override func draw(_ rect: CGRect) {

Expand Down
58 changes: 55 additions & 3 deletions CustomView/Views/ProgressCircleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ProgressCircleView: UIView {
var progressValue:CGFloat = 0.0 {
didSet{
setNeedsDisplay()
progressLabel?.text = String(format: "Progress: %.2f%%", progressValue * 100)
}
}

Expand All @@ -27,6 +28,7 @@ class ProgressCircleView: UIView {
var targetValue:CGFloat = 0.75 {
didSet{
setNeedsDisplay()
targetLabel?.text = String(format: "Target: %.2f%%", targetValue * 100)
}
}

Expand All @@ -38,13 +40,53 @@ 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 prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}

override func awakeFromNib() {
super.awakeFromNib()

targetLabel = UILabel()
targetLabel.font = UIFont(name: "Avenir Next", 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: "Avenir Next", 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 Down Expand Up @@ -95,4 +137,14 @@ class ProgressCircleView: UIView {
context?.addArc(center: centerPoint, radius: radius, startAngle: start, endAngle: progressEnd, clockwise: false)
context?.strokePath()
}

func hideLabels() {
progressLabel.isHidden = true
targetLabel.isHidden = true
}

func showLabels() {
progressLabel.isHidden = false
targetLabel.isHidden = false
}
}