UITabBar "barTintColor" Does Not Change Back to Light Mode Color in SwiftUI

I created an app with a TabBar and utilized AppDelegate to control it's background color using the code below. I have a custom ColorSet in Assets ("headerFooter") that sets the Light and Dark mode colors for my TabBar. The app will not change the TabBar back to the correct Light Mode color when I change from Dark to Light in the simulator or on my iPhone X.


I am using Catalina v10.15 beta (19A578c) and Xcode 11.2 beta. My iPhone is running iOS 13.1.2.


With the phone in Dark Mode, I open the app and it opens with the correct colors. Conversely, when I start the app with the phone in Light Mode, the app opens with the correct colors. When I change from Light Mode to Dark Mode, the colors change accordingly. However whenever I change from Dark Mode to Light Mode, the TabBar remains showing the Dark Mode color.


UITabBar.appearance().barTintColor = UIColor(name: "headerFooter")


Any ideas?


Thanks,

Doug

Accepted Reply

Where in the AppDelegate are you using this code?

Also, if this is a SwiftUI app, you'll have better luck setting the colors on "TabView" itself using a modifer.

SwiftUI will automatically re-render your views when you switch to and from dark mode.


I imagine the issue here is the AppDelegate method that you're using isn't being called again after you change to (and from) dark mode.

Replies

Where in the AppDelegate are you using this code?

Also, if this is a SwiftUI app, you'll have better luck setting the colors on "TabView" itself using a modifer.

SwiftUI will automatically re-render your views when you switch to and from dark mode.


I imagine the issue here is the AppDelegate method that you're using isn't being called again after you change to (and from) dark mode.

I am using the code in the "didFinishLaunchingWithOptions" function. And I completely agree with you that this function is not being called again when I change back to "light mode". I have tried all manner of options to set the tabBar background in TabView with zero luck.


I will mark your answer as correct since you point out the AppDelegare function is not being called again... this makes complete sense. But I'm still searching for a solution.


Thanks for weighing-in... I really appreciate it.

Hello! Did you find the solution for correct changing colors for tabview. I also used UITabBar.appearance().barTintColor = UIColor(name: "headerFooter") in init and it works well for NavigationBar, but not for TabBar