Search code examples
swiftuiswiftui-tabview

SwiftUI TabView accentColor(:_) deprecated


I have a tabView and I'm trying to change it's color. Using accentColor(:_) works but it's going to be deprecated.

TabView {
            AppetizerListView()
                .tabItem {
                    Image(systemName: "house")
                    Text("Home")
                }
            AccountView()
                .tabItem {
                    Image(systemName: "person")
                    Text("Account")
                }
            OrderView()
                .tabItem {
                    Image(systemName: "bag")
                    Text("Order")
                }
        }
        .accentColor(Color("brandPrimary"))

Instead I've tried to use .tint(:_) as Apple suggests but is not working (it builds but does not change the color).

TabView {
            AppetizerListView()
                .tabItem {
                    Image(systemName: "house")
                    Text("Home")
                }
            AccountView()
                .tabItem {
                    Image(systemName: "person")
                    Text("Account")
                }
            OrderView()
                .tabItem {
                    Image(systemName: "bag")
                    Text("Order")
                }
        }
        .tint(Color("brandPrimary"))

I also tried using .tint(_:) in each TabItem but it's also not working.

Any idea of what's going on or which is the correct way of making my code work as expected without using deprecated functions?

Maybe I'm using tint in a wrong way

Thanks!


Solution

  • I've found the solution to the problem, but I'll leave the post here for anyone who has the same problem.

    What you have to do is to go to the Assets folder and define the AccentColor (that it has to be already created) as the color that you want your bar to be.

    No modifiers have to be added to the tabView and it will automatically be showing the tabView with the color you defined as the AccentColor in your Assets folder.