Nikita Velichkin

Dark Mode in iOS

By the iOS 13 users are allowed to set colour mode - light or dark. So all the developing applications have to be adapted to the both designs. All the colours that were created with hex, colorLiteral are becoming unadapted to colour schemes. For this moment there is a number of approaches to create a "dynamic" colour.
Nikita Vekichkin
iOS Developer
UIElementColor
New colour standard for work with standard objects from UIKit is UIElementColor that available in iOS 13.
This standard contains colours that can be adapted to design's choice. For example, it's required to use UIColor.label colour for main text and UIColor.systemBackground for sheets/collections/views.
These colours have white colour on dark mode and black on light mode.
The whole objects list you can find in documentation.
Also Apple added an adapting support for system colours and now there's a prefix "system" (pic. 1).
Pic. 1. Adapted colours
Dynamic Provider
Now there's a new approach to initialize UIColor with dynamic provider.
With this initializator you can add adapted colours and use it in code.
Color Asset
Also you can create colours with Color Set through Asset Catalog.
Pic. 2. Creation of Colour
After colour creation in Appearance tab you have to choose "Any, Dark" or "Any, Dark, Light".
Pic. 3. Appearance changing.
Further you can see two or three blocks and choose colour for each of them (pic. 4). Then use this colour in InterfaceBuilder by the colour choice from list or add extension on UIColor.
Pic. 4. Completed colour.
Thanks for reading!