How Button & function work in swiftUI
Saurabh Chavan

Saurabh Chavan @100rabhcsmc

About: React Native,iOS, SwiftUI 💻🥣🛌🔄

Location:
Pune,Maharashtra
Joined:
Jun 26, 2020

How Button & function work in swiftUI

Publish Date: Feb 6 '23
0 0

When we click on the button then value will update on the screen

import SwiftUI

struct ContentView: View {
    @State private var name = ""

    var body: some View {
        VStack{
            Button("click me",role: .destructive, action: Clicked).buttonStyle(.borderedProminent).tint(.green).foregroundColor(.black)
            Text("Hello \(name)")
        }
    }

      func Clicked(){
               name = "Saurabh"
            }

}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Comments 0 total

    Add comment