Swift Dark / ​Light mode

Apple has recently made available the dark or light themes for its OS. I have not yet done the repo swift weareopensource, however it should arrive quickly. So I'm starting to include this kind of news in our blog, take the opportunity to share it with you.

Swift Dark / ​Light mode

Apple has recently made available the dark or light themes for its OS. I have not yet done the repo swift weareopensource, however, it should arrive quickly. So I'm starting to include this kind of news in our blog, take the opportunity to share it with you.

You can find here what this has given in PR (also contains some design changes), and here is some information :

Color Assets

You can begin by setting colors in your project assets, with light and dark mode :

Then you can call them in the code :

UIColor(named: "waosSurface")

a suggestion on this point, which I realized, would be to call these names of colors from a configuration file :). This will allow you to easily manage x themes.

"themes": {
    "waos" :{
        "primary": "waosPrimary",
    }
}


And finally, you can observe the changes easily on the interface :


This can work the same way for images :)

Detect Light or Dark mode :

if traitCollection.userInterfaceStyle == .light {
   ...
} else {
   ...
}

for example, on my side, it serves me to darken or lighten the background of a button when the user presses it :), depending on the active theme.