Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Adopting Dark Mode

Eeb061c8b2816b771920da1b3e7904a3?s=47 Swift India
September 14, 2019

Adopting Dark Mode

Presentation Video: https://www.youtube.com/watch?v=fwBc-jEky2E

Overview of the new API added to aid implementation of API on iOS 13. We'll cover mainly the dynamic UIColor objects, how to deal with the compatibility on older iOS versions & some common issues & gotchas.

Speaker: Nishant Desai, iOS Engineer at PSPDFKit

Presented at Swift Mumbai Chapter X Meetup hosted by WeWork Goregaon


Swift India

September 14, 2019


  1. Adopting Dark Mode Nishant Desai iOS Engineer @ PSPDFKit twitter.com/nish_desai

  2. Dark Mode… why? • System level support. • Easier on

    the eyes. • Kind on battery. • …. it looks amazing!
  3. How it works? • Trait collections (UITraitCollection) • Dynamic Colors

  4. New User Interface Traits • UIAccessibilityContrast - Constrast. • UILegibilityWeight

    - Font weight (bold text value). • UIUserInterfaceStyle - light / dark mode. • UIUserInterfaceLevel - Visual level.
  5. • UIUserInterfaceStyleUnspecified? • UITraitCollectionChangeLoggingEnabled • UITraitCollection.current

  6. Enforcing user interface style • UIUserInterfaceStyle in Info.plist. • Set

    `overrideUserInterfaceStyle` to have a specific style for view elements (UIView, UIViewController). • Use overrideTraitCollection to override specific traits. • Only supported on UIViewController and UIPresentationController.
  7. Creating Dynamic Colors Dynamic Provider Init Asset Catalog

  8. Safe Methods UITraitCollection.currentTraitCollection updated by UIKit in below methods

  9. Resolving Dynamic Colors • Dynamic colors are only supported by

    UIKit. • Core Graphics uses static color. • Methods to resolve colors:
  10. None
  11. UI Element Colors • Dynamic colors which adapt to all

    system appearances. • Colors defined for background color usage, label, separators and fill. • New primary system colors.
  12. Dynamic Images • Asset Catalog supports adding dynamic images. •

    Use imageAsset property to resolve dynamic images. • Use UIImageView trait collections. • Use UIImage.withTintColor(_:) to create a dynamically tinting image.
  13. Backwards Compatibility • All the API discussed are only available

    iOS 13 and above. • Consider using extensions and categories as wrappers around them.
  14. Thank You.