SwiftUI-Button

原文:https://iosdevcenters.blogspot.com/2019/09/swiftui-button-example-with-action.html

import SwiftUI

struct ContentView: View {
    @State private var showiOSDetail = false

    var body: some View {
        VStack {
            Button(action: {
                self.showiOSDetail.toggle()
            }) {
                Text("iOS Blog")
                .foregroundColor(Color.white)
            }
            .padding()
            .background(Color.blue)

            if showiOSDetail {
                Text("You are click on iOsDevCenters ")
                    .font(.headline)
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

效果如图:


SwiftUI-Button_第1张图片
image.png

你可能感兴趣的:(SwiftUI-Button)