-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathViewController.swift
110 lines (92 loc) · 3.44 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// ViewController.swift
// ProcessLoadingViewDemo
//
// Created by Ayman Ibrahim on 1/12/18.
// Copyright © 2018 Ayman Ibrahim. All rights reserved.
//
import UIKit
@available(iOS 10.0, *)
class ViewController: UIViewController
{
@IBOutlet weak var viewProcess: ProcessLoadingView!
var options = ProcessOptions()
let colorBlue = UIColor(displayP3Red: 100/255, green: 217/255, blue: 213/255, alpha: 1)
let colorOrange = UIColor(displayP3Red: 191/255, green: 155/255, blue: 124/255, alpha: 1)
let bgColor = UIColor(displayP3Red: 82/255, green: 75/255, blue: 96/255, alpha: 1)
override func viewDidLoad()
{
super.viewDidLoad()
let step = 3
let totalSteps = 8
let curvesStartRadians = [(3 * CGFloat.pi)/2, (23 * CGFloat.pi) / 12, (CGFloat.pi / 3), ((2 * CGFloat.pi) / 3), (13 * CGFloat.pi) / 12]
let curvesEndRadians = [(23 * CGFloat.pi) / 12, (CGFloat.pi) / 3, (2 * CGFloat.pi) / 3, (13 * CGFloat.pi) / 12, (3 * CGFloat.pi)/2]
options.curvesStartRadians = curvesStartRadians
options.curvesEndRadians = curvesEndRadians
options.setNumberOfItems(number: totalSteps)
options.stepComplete = step
options.inSpeed = 1.2
options.images = imageOpts(of: step, totalSteps: totalSteps)
options.mainTextfont = UIFont.boldSystemFont(ofSize: 22)
options.subTextfont = UIFont.boldSystemFont(ofSize: 16)
options.ItemSize = 30
options.radius = 120
options.bgColor = bgColor
options.completedPathColor = colorBlue
options.mainTextColor = .white
options.subTextColor = colorOrange
viewProcess.options = options
}
//-------------------------
//MARK: - Actions -
@IBAction func start(_ sender: UIButton)
{
options.mainText = "CLEANING"//randomString(length: 9)
options.subText = "IN PROCESS"
viewProcess.start(completed:
{
print("done")
})
}
@IBAction func replay(_ sender: UIButton)
{
viewProcess.reset(removeItems: false, completed: nil)
}
@IBAction func reset(_ sender: Any)
{
viewProcess.reset(removeItems: true, completed: nil)
}
//100 217 213
//191 155 124
func imageOpts(of stepNumber:Int, totalSteps:Int) ->[(UIImage, UIColor?)]
{
var optsImages = [(UIImage, UIColor?)]()
for i in 0 ..< totalSteps
{
if stepNumber > i
{
optsImages.append((#imageLiteral(resourceName: "checkMark"), colorBlue))
}
else if stepNumber == i
{
optsImages.append((#imageLiteral(resourceName: "emptyCircle"), colorOrange))
}
else
{
optsImages.append((#imageLiteral(resourceName: "emptyCircle"), UIColor.gray))
}
}
return optsImages
}
func randomString(length: Int) -> String {
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
let len = UInt32(letters.length)
var randomString = ""
for _ in 0 ..< length {
let rand = arc4random_uniform(len)
var nextChar = letters.character(at: Int(rand))
randomString += NSString(characters: &nextChar, length: 1) as String
}
return randomString
}
}