Skip to content

Commit 35a510b

Browse files
committed
Update "groove" size for separate adjustment of lines width
1 parent 5692c05 commit 35a510b

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

ALProgressRing.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "ALProgressRing"
3-
spec.version = "1.0.0"
3+
spec.version = "1.1.0"
44
spec.summary = "Animated and fully customizable progress ring with gradient"
55

66
spec.homepage = "https://github.com/alxrguz/ALProgressRing"

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ progressRing.startAngle = -.pi / 2 // The start angle of the ring to begin drawi
127127
progressRing.endAngle = 1.5 * .pi // The end angle of the ring to end drawing.
128128
progressRing.startGradientPoint = .init(x: 0.5, y: 0) // The starting poin of the gradient
129129
progressRing.endGradientPoint = .init(x: 0.5, y: 1) // The ending position of the gradient.
130-
progressRing.ringWidth = 10 // Width of the progress ring.
131-
progressRing.grooveWidth = 8 // Width of the background "groove" ring.
130+
131+
// Sets the line width for progress ring and "groove" ring
132+
progressRing.lineWidth = 10
133+
// Or, if you need to separate these parameters, use
134+
progressRing.ringWidth = 10
135+
progressRing.grooveWidth = 8
132136
```
133137

134138

Sources/ALProgressRing/Views/ALProgressRing.swift

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ import UIKit
2626
open class ALProgressRing: UIView {
2727

2828
// 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+
2939
/// The line width of the progress ring.
3040
public var ringWidth: CGFloat = 10 {
3141
didSet {
@@ -82,8 +92,21 @@ open class ALProgressRing: UIView {
8292
public var timingFunction: ALTimingFunction = .easeOutExpo
8393

8494
/// 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
87110
}
88111

89112
/// 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 {
196219

197220
private func configureRing() {
198221
let ringPath = self.ringPath()
222+
let groovePath = self.groovePath()
199223
grooveLayer.frame = bounds
200-
grooveLayer.path = ringPath
224+
grooveLayer.path = groovePath
201225

202226
ringLayer.frame = bounds
203227
ringLayer.path = ringPath
@@ -208,7 +232,13 @@ open class ALProgressRing: UIView {
208232

209233
private func ringPath() -> CGPath {
210234
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)
212242
return circlePath.cgPath
213243
}
214244
}

0 commit comments

Comments
 (0)