-1

I want to change my unselected tabbar button color. And i did some research about that on Stackoverflow. I applied the suggestions to my code but for some reason i didn't work for me. For example, I want to make my unselected tabbar button to pink color. How could i do that? I am sharing the screenshots of Main.storyboard tabbar selectionsenter image description here

Also I am sharing my AppDelegate file:

    if #available(iOS 13.0, *) {
        let tabbar = UITabBarController()
        tabbar.tabBar.unselectedItemTintColor = .systemPink
    }

    
    return true
}
ahtctn
  • 15
  • 5
  • 1
    You're changing the unselected tint color of a throwaway tab bar controller. Either set it on the actual tab bar controller instance or on the appearance proxy. – HangarRash Aug 03 '23 at 22:42
  • Can you give me more details about that please? – ahtctn Aug 03 '23 at 22:48

1 Answers1

0

Write this in your appDelegate - didFinishWithLaunching

Below line of code sets the tint color for the selected tab bar item. In this case, it's being set to blue. The "selected" tab bar item refers to the tab that is currently active or highlighted.

UITabBar.appearance().tintColor = .systemPink

Below line of code sets the tint color for the unselected tab bar items, which are the tabs that are not currently active or highlighted. In this case, the unselected items will be tinted in system pink color.

UITabBar.appearance().unselectedItemTintColor = .systemPink

You have assigned a class to UITabbar from storyboard - If you are going to use above code please remove that tabbar class from storyboard and if you want to keep that class, there should be a property to modify unselected tint. There is no point to manipulate native UITabbar's tint while you are using custom class for it.

Remember, it's important to make sure that any custom class you've assigned to the tab bar in the storyboard is not conflicting with the changes you're making programmatically. If you're still facing issues, consider providing more so I can assist you further.