HomeiOS DevelopmentHow can I modify the background colour of the chosen tab in...

How can I modify the background colour of the chosen tab in SwiftUI TabView?


I need to add a background colour like under:

How can I modify the background colour of the chosen tab in SwiftUI TabView?

I attempted to realize it by including a ZStack, however was not profitable and getting a view like this:

Current attempt

TabView(choice: $coordinator.selectedTab) {
    // Chat Tab
    NavigationStack(path: coordinator.pathBinding(for: .chat)) {
        coordinator.buildRootView(tab: .chat)
            .toolbarVisibility(.hidden, for: .navigationBar)
    }
    .tag(Tab.chat)
    .tabItem {
        Label{
            Textual content("Chat")
        } icon: {
            ZStack {
                if coordinator.selectedTab == .chat {
                    RoundedRectangle(cornerRadius: 8)
                        .fill(tokens.componentColors.Utility.Model.utilityBrand100)
                        .body(width: 32, top: 32)
                }
                Picture("Vector")
                    .renderingMode(.template)
            }
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments