I’m trying to implement a circular progress view that looks like so:
<code>struct SpeedometerView: View {
var body: some View {
ZStack {
Color.black.edgesIgnoringSafeArea(.all)
speedProgressView(width: 300)
}
}
private func speedProgressView(width: CGFloat) -> some View {
ZStack {
Circle()
.trim(from: 0, to: 0.2)
.stroke(.red, style: StrokeStyle(lineWidth: 4, lineCap: .round))
.shadow(color: .green, radius: 10, x: 0, y: 0)
.shadow(color: .green, radius: 2, x: 0, y: 0)
}
.frame(width: width)
.rotationEffect(.degrees(100))
}
}
#Preview {
SpeedometerView()
}
</code>
<code>struct SpeedometerView: View {
var body: some View {
ZStack {
Color.black.edgesIgnoringSafeArea(.all)
speedProgressView(width: 300)
}
}
private func speedProgressView(width: CGFloat) -> some View {
ZStack {
Circle()
.trim(from: 0, to: 0.2)
.stroke(.red, style: StrokeStyle(lineWidth: 4, lineCap: .round))
.shadow(color: .green, radius: 10, x: 0, y: 0)
.shadow(color: .green, radius: 2, x: 0, y: 0)
}
.frame(width: width)
.rotationEffect(.degrees(100))
}
}
#Preview {
SpeedometerView()
}
</code>
struct SpeedometerView: View {
var body: some View {
ZStack {
Color.black.edgesIgnoringSafeArea(.all)
speedProgressView(width: 300)
}
}
private func speedProgressView(width: CGFloat) -> some View {
ZStack {
Circle()
.trim(from: 0, to: 0.2)
.stroke(.red, style: StrokeStyle(lineWidth: 4, lineCap: .round))
.shadow(color: .green, radius: 10, x: 0, y: 0)
.shadow(color: .green, radius: 2, x: 0, y: 0)
}
.frame(width: width)
.rotationEffect(.degrees(100))
}
}
#Preview {
SpeedometerView()
}
Both ends are rounded as of now due to the stroke style. How do I trim/clip only the circle end that progresses clockwise unless progress is 100% ?
Any help is appreciated.