How can I change the background color of the selected tab in SwiftUI TabView?

I want to add a background color like below:

Required implementation

I tried to achieve it by adding a ZStack, but was not successful and getting a view like this:

Current attempt

TabView(selection: $coordinator.selectedTab) { // Chat Tab NavigationStack(path: coordinator.pathBinding(for: .chat)) { coordinator.buildRootView(tab: .chat) .toolbarVisibility(.hidden, for: .navigationBar) } .tag(Tab.chat) .tabItem { Label{ Text("Chat") } icon: { ZStack { if coordinator.selectedTab == .chat { RoundedRectangle(cornerRadius: 8) .fill(tokens.componentColors.Utility.Brand.utilityBrand100) .frame(width: 32, height: 32) } Image("Vector") .renderingMode(.template) } } } }

Take Your Experience to the Next Level

New

Download our mobile app for a faster and better experience.

Comments

0
U

Join the discussion

Sign in to leave a comment

0:000:00