Skip to content

Commit

Permalink
Merge pull request #1 from grovdata/main
Browse files Browse the repository at this point in the history
Add support for setting different width of the progress/background lines
  • Loading branch information
alxrguz authored Oct 13, 2020
2 parents 67c9b20 + caaa2ad commit 5692c05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ progressRing.startAngle = -.pi / 2 // The start angle of the ring to begin drawi
progressRing.endAngle = 1.5 * .pi // The end angle of the ring to end drawing.
progressRing.startGradientPoint = .init(x: 0.5, y: 0) // The starting poin of the gradient
progressRing.endGradientPoint = .init(x: 0.5, y: 1) // The ending position of the gradient.
progressRing.ringWidth = 10 // Width of the progress ring.
progressRing.grooveWidth = 8 // Width of the background "groove" ring.
```


Expand Down
21 changes: 13 additions & 8 deletions Sources/ALProgressRing/Views/ALProgressRing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ import UIKit
open class ALProgressRing: UIView {

// MARK: Properties
/// The line width of the ring.
public var lineWidth: CGFloat = 10 {
/// The line width of the progress ring.
public var ringWidth: CGFloat = 10 {
didSet {
ringLayer.lineWidth = lineWidth
grooveLayer.lineWidth = lineWidth
ringLayer.lineWidth = ringWidth
}
}

/// The line width of the groove ring.
public var grooveWidth: CGFloat = 10 {
didSet {
grooveLayer.lineWidth = grooveWidth
}
}

Expand Down Expand Up @@ -77,7 +83,7 @@ open class ALProgressRing: UIView {

/// The radius of the ring.
public var radius: CGFloat {
return min(bounds.height, bounds.width) / 2 - lineWidth / 2
return min(bounds.height, bounds.width) / 2 - ringWidth / 2
}

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

private func styleRingLayer() {
grooveLayer.strokeColor = grooveColor.cgColor
grooveLayer.lineWidth = lineWidth
grooveLayer.lineWidth = grooveWidth

ringLayer.lineWidth = lineWidth
ringLayer.lineWidth = ringWidth
ringLayer.strokeColor = UIColor.black.cgColor
ringLayer.strokeEnd = min(progress, 1.0)
ringLayer.lineWidth = lineWidth

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

0 comments on commit 5692c05

Please sign in to comment.