Change VStack color with a button inside an HStack

HI all,
New to Xcode and coding. Taking the first steps
Have a VStack then there is an HStack with a button. What i would like to know is when I press the button inside the HStack it will change the background color of the VStack, from black to other color.
Here is a sample of the code.
Thanks all for the time to reply and help.


import SwiftUI
struct ContentView: View {

@State var index = 0

var body: some View {
Code Block
VStack{
Spacer()
CustomTabs(index: self.$index)
}.background(Color.black)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct CustomTabs : View {

@Binding var index : Int

var body: some View {
Code Block
HStack{
Button(action: {
self.index = 0
}) {
Spacer()
Image("fdt")
Spacer()
}
Why don't you set the background color in the action of the button?
Code Block
struct ContentView: View {
@State var index = 0
@State var vstackColor: Color? = .black
var body: some View {
VStack{
Spacer()
CustomTabs(index: $index,
color: $vstackColor)
}.background(vstackColor ?? Color.black)
}
}
struct CustomTabs : View {
@Binding var index : Int
@Binding var color: Color?
var body: some View {
HStack{
Button(action: {
self.index = 0
self.color = .red //Other color
}) {
Spacer()
Image("fdt")
Spacer()
}
}
}
}


Thanks.

That worked perfectly.

Appreciate the time to help.
Change VStack color with a button inside an HStack
 
 
Q