Search code examples
iosappdelegatetintcolorios-darkmodeuitraitcollection

How do I detect dark/light mode changes in my AppDelegate in order to reset global tintColor?


In my AppDelegate, I set the global tint color. How can I be notified when the user enables/disables dark mode in order to reset global tint?

In my AppDelegate, I have:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    var window: UIWindow?    // To conform with UIApplicationDelegate

    func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [ UIApplication.LaunchOptionsKey : Any ]? ) -> Bool
    {
        window?.tintColor = UIColor.someColor
        ...
    }
}

I need to update the global tint color when dark mode is enabled/disabled. How can I detect this change?


Solution

    • Define the color for light and dark appearance in the Asset Catalog
    • Set the tint color in AppDelegate with the UIColor(named: API. The color will change automatically.