Member-only story
Theming SwiftUI App with Dark and Light mode Support
Compile with Xcode 11.5
2 min readJun 7, 2020
MacOS and iOS support Light and dark mode. So it is important to make our Theme adaptive to dark and light mode. SwiftUI have inbuild support for Dark and light mode.
Setting Adaptive Colors:
For this we are going to use xcassets’s color set for following reasons:
- Color set adapts to theme(light or dark) so no need to add additional switch cases on color class to switch colors with respect to different themes.
- Color set help visualise colors then and there. It makes it easier to relate colors to designs provided by designer
- Color set allow to input colors in all format(e.g. RGB, 8-bit, Hexadecimal) so we do not have to put a conversion algorithm. Xcode do the conversion to floating point.
Now, We adapt all these colors with extension on Color so that we get proper interface to use these colors