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
8 changes: 6 additions & 2 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 */; };
A45D2903229ED1B400B3D967 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45D2902229ED1B400B3D967 /* Constants.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>"; };
A45D2902229ED1B400B3D967 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -76,6 +78,7 @@
92949A532295DAF7008EE240 /* Assets.xcassets */,
92949A552295DAF7008EE240 /* LaunchScreen.storyboard */,
92949A582295DAF7008EE240 /* Info.plist */,
A45D2902229ED1B400B3D967 /* Constants.swift */,
);
path = CustomView;
sourceTree = "<group>";
Expand Down Expand Up @@ -165,6 +168,7 @@
92FB2169229A55C5000AF93E /* ProgressBarViewController.swift in Sources */,
92949A602295DBF8008EE240 /* ProgressCircleView.swift in Sources */,
92949A4D2295DAF3008EE240 /* AppDelegate.swift in Sources */,
A45D2903229ED1B400B3D967 /* Constants.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -311,7 +315,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 34E95R7U23;
DEVELOPMENT_TEAM = L76X5KFZD9;
INFOPLIST_FILE = CustomView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -329,7 +333,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 34E95R7U23;
DEVELOPMENT_TEAM = L76X5KFZD9;
INFOPLIST_FILE = CustomView/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Binary file not shown.
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>
306 changes: 303 additions & 3 deletions CustomView/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions CustomView/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Helper.swift
// CustomView
//
// Created by Artur Carneiro on 29/05/19.
// Copyright © 2019 Joaquim Pessoa Filho. All rights reserved.
//

import Foundation
import UIKit

enum ColorPallete {
static let red = #colorLiteral(red: 0.9764705882, green: 0.3411764706, blue: 0.2196078431, alpha: 1)
static let orange = #colorLiteral(red: 0.9764705882, green: 0.5333333333, blue: 0.2117647059, alpha: 1)
static let yellow = #colorLiteral(red: 0.9764705882, green: 0.7607843137, blue: 0.2117647059, alpha: 1)
static let green = #colorLiteral(red: 0.737254902, green: 0.9764705882, blue: 0.2117647059, alpha: 1)
static let blue = #colorLiteral(red: 0.2117647059, green: 0.9764705882, blue: 0.9254901961, alpha: 1)
static let indigo = #colorLiteral(red: 0.2117647059, green: 0.568627451, blue: 0.9764705882, alpha: 1)
static let violet = #colorLiteral(red: 0.5843137255, green: 0.2117647059, blue: 0.9764705882, alpha: 1)
}
31 changes: 31 additions & 0 deletions CustomView/Controllers/ProgressBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ class ProgressBarViewController: UITableViewController {
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!

@IBOutlet weak var progressSegmentedColorPicker: UISegmentedControl!
@IBOutlet weak var targetSegmentedColorPicker: UISegmentedControl!

private var colorArray : [UIColor] = [ColorPallete.red, ColorPallete.orange, ColorPallete.yellow, ColorPallete.green, ColorPallete.blue, ColorPallete.indigo, ColorPallete.violet]

override func viewDidLoad() {
super.viewDidLoad()

self.progressBarView?.lineWidth = CGFloat(self.widthSlider.value)
self.progressBarView?.progressValue = CGFloat(self.progressSlider.value)
self.progressBarView?.targetValue = CGFloat(self.targetSlider.value)

colorPickerApply(on: progressSegmentedColorPicker)
colorPickerApply(on: targetSegmentedColorPicker)
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand All @@ -40,5 +48,28 @@ class ProgressBarViewController: UITableViewController {
@IBAction func targetChange(_ sender: Any) {
self.progressBarView?.targetValue = CGFloat(self.targetSlider.value)
}

@IBAction func changeProgressColor(_ sender: UISegmentedControl) {

progressBarView?.progressColor = colorArray[sender.selectedSegmentIndex]
progressSlider.tintColor = colorArray[sender.selectedSegmentIndex]

}

@IBAction func changeTargetColor(_ sender: UISegmentedControl) {

progressBarView?.targetColor = colorArray[sender.selectedSegmentIndex]
targetSlider.tintColor = colorArray[sender.selectedSegmentIndex]

}

func colorPickerApply(on segmented : UISegmentedControl) {

for i in 0..<segmented.subviews.count {
let aux : UIView = segmented.subviews[i] as UIView
aux.tintColor = colorArray[i]
}

}
}

91 changes: 91 additions & 0 deletions CustomView/Controllers/ProgressCircleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,126 @@ import UIKit

class ProgressCircleViewController: UITableViewController {

@IBOutlet weak var progressCircleView3: ProgressCircleView!
@IBOutlet weak var progressCircleView2: ProgressCircleView!
@IBOutlet weak var progressCircleView: ProgressCircleView?

@IBOutlet weak var widthSlider: UISlider!
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!

@IBOutlet weak var progressPercentageLabel: UILabel!
@IBOutlet weak var targetPercentageLabel: UILabel!

@IBOutlet weak var progressSegmentedColorPicker: UISegmentedControl!
@IBOutlet weak var targetSegmentedColorPicker: UISegmentedControl!

private var percentageProgress : Float?
private var percentageTarget : Float?

private var colorArray : [UIColor] = [ColorPallete.red, ColorPallete.orange, ColorPallete.yellow, ColorPallete.green, ColorPallete.blue, ColorPallete.indigo, ColorPallete.violet]



override func viewDidLoad() {

super.viewDidLoad()

widthSlider.value = 10

self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)

self.progressCircleView2?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView2?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView2?.targetValue = CGFloat(self.targetSlider.value)

self.progressCircleView3?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView3?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView3?.targetValue = CGFloat(self.targetSlider.value)

percentageTarget = self.targetSlider.value * 100
guard let percentageTarget = percentageTarget else { return }
targetPercentageLabel.text = String(format: "%.2f", percentageTarget) + "%"

percentageProgress = self.progressSlider.value * 100
guard let percentageProgress = percentageProgress else { return }
progressPercentageLabel.text = String(format: "%.2f", percentageProgress) + "%"

colorPickerApply(on: progressSegmentedColorPicker)
colorPickerApply(on: targetSegmentedColorPicker)

}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

super.viewWillTransition(to: size, with: coordinator)

self.progressCircleView?.setNeedsDisplay()
self.progressCircleView2?.setNeedsDisplay()
self.progressCircleView3?.setNeedsDisplay()

}

@IBAction func widthChange(_ sender: Any) {

self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView2?.circleWidth = CGFloat(self.widthSlider.value)
self.progressCircleView3?.circleWidth = CGFloat(self.widthSlider.value)

}

@IBAction func progessChange(_ sender: Any) {

self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView2?.progressValue = CGFloat(self.progressSlider.value)
self.progressCircleView3?.progressValue = CGFloat(self.progressSlider.value)

percentageProgress = self.progressSlider.value * 100
guard let percentageProgress = percentageProgress else { return }
progressPercentageLabel.text = String(format: "%.2f", percentageProgress) + "%"
}

@IBAction func targetChange(_ sender: Any) {

self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)
self.progressCircleView2?.targetValue = CGFloat(self.targetSlider.value)
self.progressCircleView3?.targetValue = CGFloat(self.targetSlider.value)

percentageTarget = self.targetSlider.value * 100
guard let percentageTarget = percentageTarget else { return }
targetPercentageLabel.text = String(format: "%.2f", percentageTarget) + "%"

}

@IBAction func changeProgressColor(_ sender: UISegmentedControl) {

progressCircleView?.progressColor = colorArray[sender.selectedSegmentIndex]
progressCircleView2?.progressColor = colorArray[sender.selectedSegmentIndex]
progressCircleView3?.progressColor = colorArray[sender.selectedSegmentIndex]
progressSlider.tintColor = colorArray[sender.selectedSegmentIndex]

}

@IBAction func changeTargetColor(_ sender: UISegmentedControl) {

progressCircleView?.targetColor = colorArray[sender.selectedSegmentIndex]
progressCircleView2?.targetColor = colorArray[sender.selectedSegmentIndex]
progressCircleView3?.targetColor = colorArray[sender.selectedSegmentIndex]
targetSlider.tintColor = colorArray[sender.selectedSegmentIndex]


}

func colorPickerApply(on segmented : UISegmentedControl) {

for i in 0..<segmented.subviews.count {
let aux : UIView = segmented.subviews[i] as UIView
aux.tintColor = colorArray[i]
}

}

}

18 changes: 15 additions & 3 deletions CustomView/Views/ProgressBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ 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) {
Expand Down
20 changes: 16 additions & 4 deletions CustomView/Views/ProgressCircleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,32 @@ class ProgressCircleView: UIView {
}

@IBInspectable
var circleWidth:CGFloat = 10.0 {
var circleWidth:CGFloat = 10 {
didSet{
setNeedsDisplay()
}
}

@IBInspectable
var circleColor:UIColor = UIColor.black
var circleColor:UIColor = UIColor.black{
didSet {
setNeedsDisplay()
}
}

@IBInspectable
var progressColor:UIColor = UIColor.yellow
var progressColor:UIColor = ColorPallete.red {
didSet {
setNeedsDisplay()
}
}

@IBInspectable
var targetColor:UIColor = UIColor.green
var targetColor:UIColor = ColorPallete.yellow {
didSet {
setNeedsDisplay()
}
}

// Method that draw the circle, progress and target
override func draw(_ rect: CGRect) {
Expand Down