Skip to content

Commit 5692c05

Browse files
authored
Merge pull request #1 from grovdata/main
Add support for setting different width of the progress/background lines
2 parents 67c9b20 + caaa2ad commit 5692c05

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ 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.
130132
```
131133

132134

Sources/ALProgressRing/Views/ALProgressRing.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ import UIKit
2626
open class ALProgressRing: UIView {
2727

2828
// MARK: Properties
29-
/// The line width of the ring.
30-
public var lineWidth: CGFloat = 10 {
29+
/// The line width of the progress ring.
30+
public var ringWidth: CGFloat = 10 {
3131
didSet {
32-
ringLayer.lineWidth = lineWidth
33-
grooveLayer.lineWidth = lineWidth
32+
ringLayer.lineWidth = ringWidth
33+
}
34+
}
35+
36+
/// The line width of the groove ring.
37+
public var grooveWidth: CGFloat = 10 {
38+
didSet {
39+
grooveLayer.lineWidth = grooveWidth
3440
}
3541
}
3642

@@ -77,7 +83,7 @@ open class ALProgressRing: UIView {
7783

7884
/// The radius of the ring.
7985
public var radius: CGFloat {
80-
return min(bounds.height, bounds.width) / 2 - lineWidth / 2
86+
return min(bounds.height, bounds.width) / 2 - ringWidth / 2
8187
}
8288

8389
/// The progress of the ring between 0 and 1. The ring will fill based on the value.
@@ -172,12 +178,11 @@ open class ALProgressRing: UIView {
172178

173179
private func styleRingLayer() {
174180
grooveLayer.strokeColor = grooveColor.cgColor
175-
grooveLayer.lineWidth = lineWidth
181+
grooveLayer.lineWidth = grooveWidth
176182

177-
ringLayer.lineWidth = lineWidth
183+
ringLayer.lineWidth = ringWidth
178184
ringLayer.strokeColor = UIColor.black.cgColor
179185
ringLayer.strokeEnd = min(progress, 1.0)
180-
ringLayer.lineWidth = lineWidth
181186

182187
gradientLayer.colors = [startColor.cgColor, endColor.cgColor]
183188
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0)

0 commit comments

Comments
 (0)