Search code examples
iosswiftstoryboard

iOS 13 DarkMode and LaunchScreen - Fallback for iOS 10


I have a blue logo on the launchscreen.storyboard on white background. For the new DarkMode introduced with iOS 13 I like to invert the colors, i.e. blue background and white logo.

As we know this can be done using named colors from the asset catalogues, which change depending on the traits of the device. This is working totally fine in iOS 11 and up but shows this error when trying to support iOS 10:

Named colors do not work prior to iOS 11.0.

I tried making a view controller for the launchscreen scene in code and set the colors there using the #ifavailable clause, but the compiler says a launchscreen may not have a custom class associated with it.

I also thought of using different launchscreen storyboards depending on the iOS version but I couldn't find anything about how to.

Anything I can do about it? How to solve this problem?

Thanks, Felix


Solution

  • As suggested here, the solution is to use a dynamic image for the background instead:

    1. Create 2 images with the flat colors for light and dark mode.
    2. Import them in your Asset Catalog and define the “Any”/“Dark” appearances.
    3. Add a UIImageView in the background of your Launch Screen with this image (“Scale to Fill”, constrained to container).

    This will compile even if your deployment target is lower than iOS 11.0, and will display the appropriate color at launch.

    Image in Asset Catalog

    Launch Screen