2

I have a tab bar whose icons I am trying to make white, however despite the fact that I am specifying the color, the icons remain grey for some reasons (despite me never actually setting them to grey).

enter image description here

The code is shown below -

struct tabViewUnique: View {
    init() {
        
        
        let appearance = UITabBarAppearance()
        appearance.backgroundColor = UIColor(Color(#colorLiteral(red: 0.7137255072593689, green: 0.10196077823638916, blue: 0.10196077823638916, alpha: 1)))
                                                   
        UITabBar.appearance().standardAppearance = appearance
        UITabBar.appearance().scrollEdgeAppearance = appearance
        UITabBar.appearance().unselectedItemTintColor = UIColor.white
        
        
    }
    
    var body: some View {
        
        TabView() {
            temp()
                .tabItem {
                    Image(systemName: "globe.americas.fill")
                }
            
            Text("Tab 2")
                .tabItem {
                    Image(systemName: "bag")
                    
                }
            Text("Tab 2")
                .tabItem {
                    Image(systemName: "plus.square")
                }
            Text("Tab 2")
                .tabItem {
                    Image(systemName: "person")
                }
        }.accentColor(.white)
    }
}

1 Answers1

0

In this case you don't need to create custom appearance instead work with default one

demo

Tested with Xcode 13.3 / iOS 15.4

UITabBar.appearance().backgroundColor = UIColor(Color(#colorLiteral(red: 0.7137255072593689, green: 0.10196077823638916, blue: 0.10196077823638916, alpha: 1)))
UITabBar.appearance().unselectedItemTintColor = UIColor.white

Complete test module in project

Asperi
  • 228,894
  • 20
  • 464
  • 690