How do I change the foreground color of a SwiftUI Tab

How do I change the foreground color of a SwiftUI Tab?

I have my code as follows:

/// Inside TabView 
// Home Tab
Tab("", systemImage: "house.fill", value: .home) {
     HomeScreen()
}.foregroundStyle(.red)

I get errors when I tried to add the foregroundStyle(.red).

I also tried using the label parameter and creating a label with the foregroundStyle(.red) modifier. Compiles but still no color changes.

Answered by Claude31 in 808741022

If I understand what you are looking for, you could use accentColor:

struct ContentView: View {
    @State var selectedIndex: Int = 1

    var body: some View {
        TabView(selection: $selectedIndex) {
            Text("Hello 1")
                .tag(1)
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            
            Text("Hello 2")
                .tag(2)
                .tabItem {
                    Image(systemName: "gearshape")
                    Text("Settings")
                }
        }
        .accentColor(Color.red)
    }
}

But now, you should use colorScheme.

Get more here: https://sarunw.com/posts/swiftui-tabbaritem-color/

And https://sarunw.com/posts/swiftui-accentcolor/

hi, try with modifier: .tint(.yellow)

If I understand what you are looking for, you could use accentColor:

struct ContentView: View {
    @State var selectedIndex: Int = 1

    var body: some View {
        TabView(selection: $selectedIndex) {
            Text("Hello 1")
                .tag(1)
                .tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            
            Text("Hello 2")
                .tag(2)
                .tabItem {
                    Image(systemName: "gearshape")
                    Text("Settings")
                }
        }
        .accentColor(Color.red)
    }
}

But now, you should use colorScheme.

Get more here: https://sarunw.com/posts/swiftui-tabbaritem-color/

And https://sarunw.com/posts/swiftui-accentcolor/

How do I change the foreground color of a SwiftUI Tab
 
 
Q