Just copy the below code and modify according to your needs.
import SwiftUI
struct SpinnerExampleView: View {
@State private var isLoading = false
var body: some View {
VStack {
if isLoading {
ProgressView("Loading...")
.progressViewStyle(CircularProgressViewStyle(tint: .blue)) // Customize color
.scaleEffect(1.5) // Adjust size
.padding()
} else {
Button("Load Data") {
loadData()
}
.padding()
}
}
.navigationTitle("Spinner Example")
}
private func loadData() {
isLoading = true
// Simulating a network call
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
isLoading = false // Stop loading after 2 seconds
}
}
}