1

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?

Gary Hooper
  • 312
  • 1
  • 13

1 Answers1

1
  • 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.
vadian
  • 274,689
  • 30
  • 353
  • 361
  • 1
    Alternatively, I was also able to achieve this by adding `traitCollectionDidChange` to each of my root view controllers. – Gary Hooper Nov 06 '19 at 18:43