@@ -26,6 +26,16 @@ import UIKit
26
26
open class ALProgressRing : UIView {
27
27
28
28
// MARK: Properties
29
+
30
+ /// Sets the line width for progress ring and groove ring.
31
+ /// - Note: If you need separate customization use the `ringWidth` and `grooveWidth` properties
32
+ public var lineWidth : CGFloat = 10 {
33
+ didSet {
34
+ ringWidth = lineWidth
35
+ grooveWidth = lineWidth
36
+ }
37
+ }
38
+
29
39
/// The line width of the progress ring.
30
40
public var ringWidth : CGFloat = 10 {
31
41
didSet {
@@ -82,8 +92,21 @@ open class ALProgressRing: UIView {
82
92
public var timingFunction : ALTimingFunction = . easeOutExpo
83
93
84
94
/// The radius of the ring.
85
- public var radius : CGFloat {
86
- return min ( bounds. height, bounds. width) / 2 - ringWidth / 2
95
+ public var ringRadius : CGFloat {
96
+ var radius = min ( bounds. height, bounds. width) / 2 - ringWidth / 2
97
+ if ringWidth < grooveWidth {
98
+ radius -= ( grooveWidth - ringWidth) / 2
99
+ }
100
+ return radius
101
+ }
102
+
103
+ /// The radius of the groove.
104
+ public var grooveRadius : CGFloat {
105
+ var radius = min ( bounds. height, bounds. width) / 2 - grooveWidth / 2
106
+ if grooveWidth < ringWidth {
107
+ radius -= ( ringWidth - grooveWidth) / 2
108
+ }
109
+ return radius
87
110
}
88
111
89
112
/// The progress of the ring between 0 and 1. The ring will fill based on the value.
@@ -196,8 +219,9 @@ open class ALProgressRing: UIView {
196
219
197
220
private func configureRing( ) {
198
221
let ringPath = self . ringPath ( )
222
+ let groovePath = self . groovePath ( )
199
223
grooveLayer. frame = bounds
200
- grooveLayer. path = ringPath
224
+ grooveLayer. path = groovePath
201
225
202
226
ringLayer. frame = bounds
203
227
ringLayer. path = ringPath
@@ -208,7 +232,13 @@ open class ALProgressRing: UIView {
208
232
209
233
private func ringPath( ) -> CGPath {
210
234
let center = CGPoint ( x: bounds. origin. x + frame. width / 2.0 , y: bounds. origin. y + frame. height / 2.0 )
211
- let circlePath = UIBezierPath ( arcCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true )
235
+ let circlePath = UIBezierPath ( arcCenter: center, radius: ringRadius, startAngle: startAngle, endAngle: endAngle, clockwise: true )
236
+ return circlePath. cgPath
237
+ }
238
+
239
+ private func groovePath( ) -> CGPath {
240
+ let center = CGPoint ( x: bounds. origin. x + frame. width / 2.0 , y: bounds. origin. y + frame. height / 2.0 )
241
+ let circlePath = UIBezierPath ( arcCenter: center, radius: grooveRadius, startAngle: startAngle, endAngle: endAngle, clockwise: true )
212
242
return circlePath. cgPath
213
243
}
214
244
}
0 commit comments