How can I change the background color of the selected tab in SwiftUI TabView?
I want to add a background color like below:

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

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
NewDownload our mobile app for a faster and better experience.
Comments
0Join the discussion
Sign in to leave a comment