Reputation: 75
How would I go about setting the background of the view with a button?
I would assume you would do something along the lines of
struct ContentView: View {
var body: some View {
Button(
action: {
self.foregroundColor(Color.red)
}
)
{
Text("Change Color")
}
}
}
But no matter what way I write it, it never works
Any help is appreciated
Upvotes: 1
Views: 35
Reputation: 258413
Here it is
@State var myColor: Color = .black
var body: some View {
Button(
action: {
self.myColor = Color.red
}
)
{
Text("Change Color")
.foregroundColor(myColor)
}
}
Upvotes: 1