Support for dark mode

Apple has introduced dark mode in iOS 13. As app developer, we should make our apps support the new features as fast as possible so the users will have a nice overall experience when enabling this new feature on their iPhone.

Most convenient way to test dark mode is by adding the dark mode toggle to the Control Centre of your iPhone.

When checking one of my own apps in the store, I could see that the most obvious problem is with the viewcontrollers where we put the background color ourself.

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
    }

In order to support dark mode, we should use one of the newly available colors…

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemBackground
    }

All new UI element colors

    /* We provide two design systems (also known as "stacks") for structuring an iOS app's backgrounds.
     *
     * Each stack has three "levels" of background colors. The first color is intended to be the
     * main background, farthest back. Secondary and tertiary colors are layered on top
     * of the main background, when appropriate.
     *
     * Inside of a discrete piece of UI, choose a stack, then use colors from that stack.
     * We do not recommend mixing and matching background colors between stacks.
     * The foreground colors above are designed to work in both stacks.
     *
     * 1. systemBackground
     *    Use this stack for views with standard table views, and designs which have a white
     *    primary background in light mode.
     */
    @available(iOS 13.0, *)
    open class var systemBackground: UIColor { get }

    @available(iOS 13.0, *)
    open class var secondarySystemBackground: UIColor { get }

    @available(iOS 13.0, *)
    open class var tertiarySystemBackground: UIColor { get }