SwiftUIでインディケーターを表示する


SwiftUIでインディケーターを表示する方法です。

SwiftUIでインディケーターを表示する

ContentView.swift

import SwiftUI

struct ContentView: View {
    @State var showingIndicator = true
    
    var body: some View {
        ZStack {
            VStack {
                Spacer()
                Button {
                    showingIndicator.toggle()
                } label: {
                    Text("Show or Hide Indicator")
                        .foregroundColor(Color.white)
                        .padding()
                        .background(Color.gray)
                        .clipped()
                }
            }
            
            if showingIndicator {
                ProgressView()
            }
        }
    }
}