-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCircularProgressView.swift
More file actions
34 lines (28 loc) · 1.01 KB
/
CircularProgressView.swift
File metadata and controls
34 lines (28 loc) · 1.01 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
import SwiftUI
struct CircularProgressView: View {
private let tintColor: Color
private let dashesesCount: Int
private let size: CGFloat
private let totalDashesCount = 8
init(progress: CGFloat, tintColor: Color = .secondary, size: CGFloat = 20.0) {
self.dashesesCount = Int(CGFloat(totalDashesCount) * progress)
self.tintColor = tintColor
self.size = size
}
var body: some View {
ZStack {
ForEach(0..<dashesesCount, id: \.self, content: { dashNumber in
Capsule()
.fill(tintColor)
.frame(width: size / CGFloat(totalDashesCount), height: size / 3.0)
.transformEffect(CGAffineTransform(translationX: 0, y: size / -3.0))
.rotationEffect(Angle(radians: CGFloat.pi * 2 * CGFloat(dashNumber) / CGFloat(totalDashesCount)))
})
}
.frame(width: size, height: size)
.opacity(0.7)
}
}
#Preview {
CircularProgressView(progress: 0.8)
}