https://developer.apple.com/documentation/swiftui/tab/init(value:content:label:)

As per the documentation link, the Tab initializer in SwiftUI should allow supplying a custom view to the Label. However, the colors used within the Label view are not being honored as expected.

I attempted to set custom colors in the Label, but they either default to system-defined styles or are ignored entirely. This behavior does not align with my understanding of how custom views should work in SwiftUI's Label.

Am I missing a step or configuration here, or is this a bug in the current implementation?

struct ContentView: View {
    @State private var activeTab: TabItem = .homeTab
    var body: some View {
        TabView(selection: $activeTab) {
            ForEach(TabItem.allCases) { tabItem in
                Tab(value: tabItem) {
                    getView(for: tabItem)
                } label: {
                    VStack(spacing: 0) {
                        MainTabButtonView(
                            selected: activeTab == tabItem,
                            tabItem: tabItem
                        )

                        Text(tabItem.title)
                    }
                }
            }
        }
    }
}

private extension ContentView {
    @ViewBuilder
    func getView(for tabItem: TabItem) -> some View {
        switch tabItem {
        case .homeTab:
            Text("Home")
        case .searchTab:
            Text("Search")
        case .profileTab:
            Text("Profile")
        case .moreTab:
            Text("More")
        }
    }
}

#Preview {
    ContentView()
}

enum TabItem: String, Identifiable, Hashable, CaseIterable {
    case homeTab
    case searchTab
    case profileTab
    case moreTab

    var tabImage: String {
        switch self {
        case .homeTab:
            "house"

        case .searchTab:
            "magnifying-glass"

        case .profileTab:
            "biographic"

        case .moreTab:
            "hamburger-menu"
        }
    }

    var title: String {
        switch self {
        case .homeTab:
            "Home"
                
        case .searchTab:
            "Search"

        case .profileTab:
            "Profile"

        case .moreTab:
            "More"
        }
    }

    var id: String {
        rawValue
    }
}


struct MainTabButtonView: View {
    private let selected: Bool
    private let tabItem: TabItem

    init(
        selected: Bool,
        tabItem: TabItem
    ) {
        self.selected = selected
        self.tabItem = tabItem
    }

    var body: some View {
        Image(tabItem.tabImage)
            .renderingMode(.template)
            .resizable()
            .aspectRatio(contentMode: .fill)
            .frame(width: 30, height: 30)
            .foregroundStyle(
                selected ? Color.green : Color.orange
            )
    }
}

Expected Behavior: The custom colors applied within the Label should render as defined.

Actual Behavior: The colors are overridden or ignored, defaulting to the system-defined styles.

Environment:

Xcode Version: Xcode 16.2 iOS: 18.2 Swift Version: Swift 6

Image(tabItem.tabImage) .symbolRenderingMode(.palette) .resizable() .aspectRatio(contentMode: .fill) .frame(width: 30, height: 30) .foregroundStyle( selected ? Color.green : Color.orange )

Changing .renderingMode(.template) to .symbolRenderingMode(.palette)

should make the active tab orange but all other tabs will be gray..

I'm currently stuck on the same problem. The label only applies the foregroundStyle for the active tab. All other tabs are gray regardless of the code.. I tried using custom buttons instead of the Tabs and that worked but then I ran into issues with the keyboard covering up textfields instead of pushing them to the top so I just went back to this until I can figure it out.. Definitely following this but I think the TabView limits customization

Thank you for your suggestion to use .symbolRenderingMode(.palette) for custom color rendering within the Label view. Unfortunately, this approach does not resolve the issue. The colors still fail to render as expected when applied within the Label of a Tab.

https://developer.apple.com/documentation/swiftui/tab/init(value:content:label:)
 
 
Q