I am trying to change colour of my Button
in SwiftUI.
This is my whole CustomButton view struct:
struct CustomButton: View {
@State private var didTap:Bool = false
var body: some View {
Button(action: {
self.didTap = true
}) {
Text("My custom button")
.font(.system(size: 24))
}
.frame(width: 300, height: 75, alignment: .center)
.padding(.all, 20)
.background(Color.yellow)
//My code above this comment works fine
//I tried something like this, but it is not working
// if didTap == true {
// .background(Color.blue)
// }
}
}
This is what my button looks like (which is fine):
But my question is: how can I change the background colour when user taps this button.
Thank you.