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 */; };
F2069BE2229DB69F006537AE /* ColorPaletteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2069BE1229DB69F006537AE /* ColorPaletteView.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>"; };
F2069BE1229DB69F006537AE /* ColorPaletteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPaletteView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,6 +75,7 @@
92949A5E2295DB10008EE240 /* Views */,
92949A4C2295DAF3008EE240 /* AppDelegate.swift */,
92949A502295DAF3008EE240 /* Main.storyboard */,
F2069BE1229DB69F006537AE /* ColorPaletteView.swift */,
92949A532295DAF7008EE240 /* Assets.xcassets */,
92949A552295DAF7008EE240 /* LaunchScreen.storyboard */,
92949A582295DAF7008EE240 /* Info.plist */,
Expand Down Expand Up @@ -164,6 +167,7 @@
92949A622295E067008EE240 /* ProgressBarView.swift in Sources */,
92FB2169229A55C5000AF93E /* ProgressBarViewController.swift in Sources */,
92949A602295DBF8008EE240 /* ProgressCircleView.swift in Sources */,
F2069BE2229DB69F006537AE /* ColorPaletteView.swift in Sources */,
92949A4D2295DAF3008EE240 /* AppDelegate.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 = RAZG7U3SR6;
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 = RAZG7U3SR6;
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,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>
520 changes: 489 additions & 31 deletions CustomView/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions CustomView/ColorPaletteView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// ColorPaletteView.swift
// CustomView
//
// Created by Rafael Galdino on 28/05/19.
// Copyright © 2019 Joaquim Pessoa Filho. All rights reserved.
//

import UIKit

@IBDesignable
class ColorPaletteView: UIView {

let colorArray = [ 0x000000, 0xfe0000, 0xff7900, 0xffb900, 0xffde00, 0xfcff00, 0xd2ff00, 0x05c000, 0x00c0a7, 0x0600ff, 0x6700bf, 0x9500c0, 0xbf0199, 0xffffff ]

override func draw(_ rect: CGRect) {
//Important constants for circle
var start:CGPoint = CGPoint(x: rect.minX, y: rect.midY)
var end:CGPoint = CGPoint(x: rect.maxX, y: rect.midY)

//Calculating end point of progress bar
let squareLength:CGFloat = rect.width / CGFloat(colorArray.count)

//starting point for all drawing code is getting the context.
let context = UIGraphicsGetCurrentContext()

//set line attributes
context?.setLineWidth(rect.height)

// Draw the MAIN line
for i in 0..<colorArray.count{
context?.setStrokeColor(uiColorFromHex(rgbValue: colorArray[i]).cgColor)
context?.move(to: CGPoint(x: start.x, y: start.y))
context?.addLine(to: CGPoint(x: end.x, y: end.y))
context?.strokePath()
start = CGPoint(x: start.x + squareLength,
y: start.y)
end = CGPoint(x: start.x + squareLength,
y: end.y)
}
}

func uiColorFromHex(rgbValue: Int) -> UIColor {

let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)

return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}

}
27 changes: 27 additions & 0 deletions CustomView/Controllers/ProgressBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ class ProgressBarViewController: UITableViewController {
@IBOutlet weak var widthSlider: UISlider!
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!
@IBOutlet weak var baseColorSlider: UISlider!
@IBOutlet weak var progressColorSlider: UISlider!
@IBOutlet weak var targetColorSlider: UISlider!

let colorArray = [ 0x000000, 0xfe0000, 0xff7900, 0xffb900, 0xffde00, 0xfcff00, 0xd2ff00, 0x05c000, 0x00c0a7, 0x0600ff, 0x6700bf, 0x9500c0, 0xbf0199, 0xffffff ]

func uiColorFromHex(rgbValue: Int) -> UIColor {

let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)

return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -40,5 +55,17 @@ class ProgressBarViewController: UITableViewController {
@IBAction func targetChange(_ sender: Any) {
self.progressBarView?.targetValue = CGFloat(self.targetSlider.value)
}
@IBAction func baseColorChange(_ sender: Any) {
self.progressBarView?.lineColor = uiColorFromHex(rgbValue: colorArray[Int(baseColorSlider.value)])
}
@IBAction func progressColorChange(_ sender: Any) {
self.progressBarView?.progressColor = uiColorFromHex(rgbValue: colorArray[Int(progressColorSlider.value)])

}
@IBAction func targetColorChange(_ sender: Any) {
self.progressBarView?.targetColor = uiColorFromHex(rgbValue: colorArray[Int(targetColorSlider.value)])
}


}

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

class ProgressCircleViewController: UITableViewController {

@IBOutlet weak var progressCircleView: ProgressCircleView?
@IBOutlet weak var widthSlider: UISlider!
@IBOutlet weak var progressSlider: UISlider!
@IBOutlet weak var targetSlider: UISlider!
@IBOutlet weak var progressCircleViews: UIView!
@IBOutlet weak var baseColorSlider: UISlider!
@IBOutlet weak var progressColorSlider: UISlider!
@IBOutlet weak var targetColorSlider: UISlider!

@IBOutlet weak var lblTargetPercent: UILabel!
@IBOutlet weak var lblProgressPercent: UILabel!

let colorArray = [ 0x000000, 0xfe0000, 0xff7900, 0xffb900, 0xffde00, 0xfcff00, 0xd2ff00, 0x05c000, 0x00c0a7, 0x0600ff, 0x6700bf, 0x9500c0, 0xbf0199, 0xffffff ]


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)
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.circleWidth = CGFloat(self.widthSlider.value)
chart.progressValue = CGFloat(self.progressSlider.value)
chart.targetValue = CGFloat(self.targetSlider.value)
}
}

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

self.progressCircleView?.setNeedsDisplay()
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.setNeedsDisplay()
}
}

@IBAction func widthChange(_ sender: Any) {
self.progressCircleView?.circleWidth = CGFloat(self.widthSlider.value)
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.circleWidth = CGFloat(self.widthSlider.value)
}
}

@IBAction func progessChange(_ sender: Any) {
self.progressCircleView?.progressValue = CGFloat(self.progressSlider.value)
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.progressValue = CGFloat(self.progressSlider.value)
}
lblProgressPercent.text = (String(Int(self.progressSlider.value * 100)) + "%")
}

@IBAction func targetChange(_ sender: Any) {
self.progressCircleView?.targetValue = CGFloat(self.targetSlider.value)
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.targetValue = CGFloat(self.targetSlider.value)
}
lblTargetPercent.text = (String(Int(self.targetSlider.value * 100)) + "%")
}


@IBAction func baseColorChange(_ sender: Any) {
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.circleColor = uiColorFromHex(rgbValue: colorArray[Int(baseColorSlider.value)])
}

}

@IBAction func progressColorChange(_ sender: Any) {
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.progressColor = uiColorFromHex(rgbValue: colorArray[Int(progressColorSlider.value)])
}
}

@IBAction func targetColorChange(_ sender: Any) {
for case
let (chart as ProgressCircleView) in self.progressCircleViews.subviews
{
chart.targetColor = uiColorFromHex(rgbValue: colorArray[Int(targetColorSlider.value)])
}
}


func uiColorFromHex(rgbValue: Int) -> UIColor {

let red = CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
let blue = CGFloat(rgbValue & 0x0000FF) / 0xFF
let alpha = CGFloat(1.0)

return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}
}

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
18 changes: 15 additions & 3 deletions CustomView/Views/ProgressCircleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,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) {
Expand Down