What are the ways to create a button and write its function?
-
If there's possibility, write a code for a button that would change its name when compressed.
import SwiftUI
struct ContentView: View {
var body: some View {
Text("gwg")
}
}struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I'm writing iOS. Swift 5, Xcode 11.
-
Create a variable.
@State var buttonName = "gwg"
Then the button itself.
Button(buttonName){ buttonName = "newName" }
Something like that. I hope I helped!