Search code examples
colorsswiftui

Change color of unselected icon in TabView (SwiftUI)


How can i change color of unselected icon (on screenshot) in TabView (SwiftUI)? Because this icon is invisible

enter image description here


Solution

  • You can use TabBarAccessor from my solution to Programmatically detect Tab Bar or TabView height in SwiftUI to change what you need as in below demo.

    Tested with Xcode 11.4 / iOS 13.4

    enter image description here

    TabView {
        Text("First View")
            .background(TabBarAccessor { tabBar in
                tabBar.unselectedItemTintColor = UIColor.red
            })
            .tabItem { Image(systemName: "1.circle") }
            .tag(0)
        Text("Second View")
            .tabItem { Image(systemName: "2.circle") }
            .tag(1)
    }
    

    Update: alternate via appearance also works

    demo

    init() {
        UITabBar.appearance().unselectedItemTintColor = UIColor.green
    }