1

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

1 Answer 1

1

Here it is

@State var myColor: Color = .black var body: some View { Button( action: { self.myColor = Color.red } ) { Text("Change Color") .foregroundColor(myColor) } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Wait, I just put the button in a ZStack and edited the code with what you gave me and I figured it out. Thank you so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.