7.7 · Trait collections, size classes, safe area, keyboard and appearance

One app runs on many screens, orientations, text sizes and colour schemes. Traits, safe areas and the appearance APIs are how a single layout adapts instead of branching on device models.

Mental model. Do not ask which device this is. Ask the environment what it is right now (traits) and which parts of the screen are usable (safe area), then let the layout follow.

Adapting to the environment

Traits and size classes, the safe area and the keyboard.

  1. What is a trait collection, and how do size classes and trait changes drive adaptive layout? 7.7.1 · L2
    A UITraitCollection describes the environment a view or controller is in: horizontalSizeClass and verticalSizeClass (compact or regular), userInterfaceStyle…
  2. What is the safe area, and how do you keep content clear of the notch, home indicator and keyboard? 7.7.2 · L2
    The safe area is the part of a view not covered by system chrome: the status bar, Dynamic Island or notch, home indicator, navigation bar and tab bar, plus any…

Look and feel

Dark mode, dynamic colours and the appearance proxy.

  1. How do dynamic colours, dark mode and the UIAppearance proxy work? 7.7.3 · L2
    Dynamic colours make dark mode nearly free. A colour such as UIColor.label, or an asset-catalogue colour with light and dark variants, or UIColor { traits in ……

More in UIKit