What is the best way to change the button's background color in SwiftUI?
I want to create a tile which is a button with centered Text and rectangular background of some color.
If you're using the .buttonStyle(style:) modifier and want to change the background color, use .tint(tint:) and not .background(alignment:content). For example, this is how you can change a .borderedProminent button style to green:
Button("Press Me!") {
//stuff to do
}
.buttonStyle(.borderedProminent)
.tint(.green)
You can add a modified directly to the button without any containers (ex: Group)
Button(action: {}) {
Text("Click me!")
}
.padding()
.foregroundColor(.white)
.background(Color.red)
Hoping to help someone!
Button(action: {self.buttonTapped()}) {
Text("Button")
.padding(.all, 12)
.foregroundColor(.white)
.background(Color.red)
}
that's how the whole bg is clickable