Skip to content

Instantly share code, notes, and snippets.

@sebsto
Created November 12, 2022 07:05
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 sebsto/d91b29a8017c5a0800aa668ac208a2c7 to your computer and use it in GitHub Desktop.
Save sebsto/d91b29a8017c5a0800aa668ac208a2c7 to your computer and use it in GitHub Desktop.
SwiftUI Loading Circle
// inspired by https://www.appcoda.com/swiftui-animation-basics-building-a-loading-indicator/
import SwiftUI
struct LoadingCircleView: View {
@State private var isLoading = false
var body: some View {
ZStack {
Circle()
.stroke(Color(.lightGray), lineWidth: 20)
Circle()
.trim(from: 0, to: 0.2)
.stroke(.tint, lineWidth: 10)
.rotationEffect(Angle(degrees: isLoading ? 360 : 0))
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: false), value: self.isLoading)
.onAppear() {
self.isLoading = true
}
}
//.frame(width:100, height:100)
.padding()
}
}
struct LoadingView_Previews: PreviewProvider {
static var previews: some View {
LoadingCircleView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment