Hi everyone,
I created a View in which a user will be able to hit a Button and set his preferred Color as the App Theme.
As you’ll be able to see below I started by defining an Array limiting user choice. I than created a ForEach loop which creates a Button for each color in my Array.
…
import SwiftUI
struct AccentColorView: View {
@Environment (.colorScheme) var colorScheme: ColorScheme
var accentColors = ["Blue", "Green", "Orange", "Pink", "Purple", "Red", "Yellow"]
var body: some View {
NavigationView {
Form {
Section(header: Text("Appearance").padding(5.0)) {
ForEach(0..<accentColors.count) { accentColor in
Button(action: {
//Set App's Accent Color
}, label: {
HStack {
Image(systemName: BSContent.accentColor)
Text(accentColors[accentColor])
}
})
}
}
}
.navigationBarTitle(Text("Accent Color"), displayMode: .inline)
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
Button(action: {
//Close Accent Color Sheet
}, label: {
Label(BTContent.close, systemImage: BSContent.close)
})
}
}
}
}
}
struct AccentColorView_Previews: PreviewProvider {
static var previews: some View {
AccentColorView()
}
}
…
Now as you probably already noticed, I added a systemImage before every color definition. My question is how do I make that systemImage change colors based on the color is in front of? I can do it if I create each button outside of my ForEach loop but how do I do it inside of it?
All possible help would be much appreciated.
Thanks!