-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathVitaminProgressbarVariant.swift
More file actions
135 lines (120 loc) · 3.82 KB
/
VitaminProgressbarVariant.swift
File metadata and controls
135 lines (120 loc) · 3.82 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// Vitamin iOS
// Apache License 2.0
//
import UIKit
import VitaminCore
public enum VitaminProgressbarVariant {
case linear(size: VitaminProgressbarLinearSize, style: VitaminProgressbarLinearStyle)
case circular(size: VitaminProgressbarCircularSize, style: VitaminProgressbarCircularStyle)
}
/// Size of the progress bar, that can be `.small`(64pt of diameter) or `.medium` (128pt of diameter)
public enum VitaminProgressbarLinearSize {
case large
/// The progress bar will be 128pt of diameter
case medium
/// The progress bar will be 64pt of diameter
case small
}
/// Style of a progress bar
public enum VitaminProgressbarLinearStyle {
/// Only the linear progress bar will be displayed
case empty
/// The progress percentage will be displayed in the center of the progress bar
case percentage
/// The left label will be displayed above the progress bar
case labelOnly
}
/// Size of the progress bar, that can be `.small`(64pt of diameter) or `.medium` (128pt of diameter)
public enum VitaminProgressbarCircularSize {
/// The progress bar will be 128pt of diameter
case medium
/// The progress bar will be 64pt of diameter
case small
}
/// Style of a progress bar
public enum VitaminProgressbarCircularStyle {
/// Only the cicular progress bar will be displayed
case empty
/// The progress percentage will be displayed in the center of the progress bar
case percentage
/// A checkered flag will be displayed in the center of the progress bar
case image(UIImage)
}
/// Type of progress bar
public enum VitaminProgressbarProgressType {
/// The progress has a detarmined length, its progress depends on the `progress`property value
case determinate
/// The progress has an undetermined length, it turns around until it is manually stopped
case indeterminate
}
// MARK: sizing properties
extension VitaminProgressbarCircularSize {
/// Diameter of the progress bar for a specific size
var outerDiameter: CGFloat {
if self == .medium {
return 128
} else {
return 64
}
}
/// Line width of the progressbar for a specific size
var lineWidth: CGFloat {
if self == .medium {
return 8
} else {
return 4
}
}
/// Text style to apply to the label for `.percentage`style for a specific size
var textStyle: VitaminTextStyle {
if self == .medium {
return VitaminTextStyle.title1
} else {
return VitaminTextStyle.body
}
}
/// Size of the image for `.image`style for a specific size
var imageSize: CGSize {
let dimension = self.outerDiameter - 2 * (self.lineWidth + 3)
return CGSize(width: dimension, height: dimension)
}
}
extension VitaminProgressbarLinearSize {
/// Line width of the progressbar for a specific size
var lineWidth: CGFloat {
switch self {
case .small:
return 4
case .medium:
return 8
case .large:
return 16
}
}
/// Text style to apply to the label for `.percentage`style for a specific size
var textStyle: VitaminTextStyle {
if self == .small {
return .footnote
} else {
return .callout
}
}
/// Spacer between texts and progress bar
var verticalSpacer: CGFloat {
if self == .small {
return 4
} else {
return 8
}
}
var labelLineHeight: CGFloat {
// extract lineHeight from text style
let paragraphStyle = self.textStyle.customAttributes()[.paragraphStyle] as? NSParagraphStyle
let lineHeight = paragraphStyle?.maximumLineHeight
if let lineHeight = lineHeight {
return lineHeight
}
return 0
}
}