I want to support 2 themes for an app. Light and Dark one. So, I have a UIButton
that allows the user to tap on it and switch between light and dark theme.
The UITabBar
has it's own class and I've set it to change accordingly to the current theme but it's not working. Not sure what I'm doing wrong.
class MainTabbar: UITabBarController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBar.barTintColor = Theme.current.tabbarTintColor
self.tabBar.tintColor = Theme.current.tabbarSelectedItems
self.tabBar.unselectedItemTintColor = Theme.current.tabbarUnselectedItemsColor
}
}
In the AppDelegate
file, I check whether there's a selected theme if not, set the LightTheme
.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Set Theme
if UserDefaults.standard.object(forKey: SelectedThemeKey) != nil {
Theme.current = UserDefaults.standard.bool(forKey: SelectedThemeKey) ? LightTheme() : DarkTheme()
print("current theme is: \(Theme.current)")
}
}
As of now, it only changes the colors of the UITabbar
IF the app is being relaunched.