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()
}
}
Output:
Top comments (0)