import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
Button("Sign In", action: signIn)
Button("Register", action: register)
}
.buttonStyle(.bordered)
}
func signIn() {}
func register() {}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
.buttonStyle(.automatic)
.buttonStyle(.plain)
Button("Tap me!") {
print("Button was tapped")
}
Or
Button(action: {
print("Button was tapped")
}) {
Text("Tap me!")
}
Button(action: {
print("Edit button was tapped")
}) {
Image(systemName: "pencil")
}
Button(action: {
print("Edit button was tapped")
}) {
HStack(spacing: 10) {
Image(systemName: "pencil")
Text("Edit")
}
}
Tip: If you find that your images have become filled in with a color, for example showing as solid blue rather than your actual picture, this is probably SwiftUI coloring them to show that they are tappable. To fix the problem, use the
renderingMode(.original)
modifier to force SwiftUI to show the original image rather than the recolored version.