Tab Bar Controller: Icon and Colors when switching to dark mode

1.9k views Asked by At

When I switch my app to dark mode this is what happens to the tab bar. How can i make the tapped icon fully visible in the dark mode environment?

im using the runtime property tintColor to automatically change the color and it's set in this way

tintColor = Label

enter image description here

1

There are 1 answers

0
Menaim On

You should use the traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) function of UIView/UIViewController to detect changes in the interface environment (including changes in the user interface style). Then after checking it you can change the color of the TabBar icons depending on the selected mode by using the below:

 UITabBar.appearance().barTintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)
        UITabBar.appearance().tintColor = #colorLiteral(red: 0.2000651062, green: 0.1960035861, blue: 0.2000851929, alpha: 1)
        UITabBar.appearance().unselectedItemTintColor = #colorLiteral(red: 0.7415059209, green: 0.5448099971, blue: 0.5051562786, alpha: 1)

and you can check your colors depending on your App.