Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created September 1, 2023 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriseidhof/8f30e82dff524a6fba05b5a14c2ece31 to your computer and use it in GitHub Desktop.
Save chriseidhof/8f30e82dff524a6fba05b5a14c2ece31 to your computer and use it in GitHub Desktop.
//
import SwiftUI
struct MyProgress: View, Animatable {
var progress: Double
var animatableData: Double {
get { progress }
set { progress = newValue }
}
var lineWidth: CGFloat = 10
var circleOpacity: CGFloat {
var start = 0.95
return max(0, progress-start)/(1-start)
}
var body: some View {
let trimmed = Circle()
.rotation(.degrees(-90))
.trim(from: 0, to: progress)
ZStack {
trimmed
.stroke(lineWidth: lineWidth)
Circle()
.frame(width: lineWidth, height: lineWidth)
.opacity(circleOpacity)
}
}
}
struct ContentView: View {
@State var progress: Double = 0
var body: some View {
VStack {
Button("Toggle") { progress = progress == 0 ? 1 : 0}
Slider(value: $progress, in: 0...1)
MyProgress(progress: progress)
.animation(.easeInOut(duration: 3), value: progress)
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment