Created
November 12, 2022 07:05
-
-
Save sebsto/d91b29a8017c5a0800aa668ac208a2c7 to your computer and use it in GitHub Desktop.
SwiftUI Loading Circle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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