DynamicTypeSize

A Dynamic Type size, which specifies how large scalable content should be.

EnumerationiOS 15.0+macOS 12.0+tvOS 15.0+watchOS 8.0+DynamicTypeSize in SwiftUI

Declaration

React
type DynamicTypeSize =
  | 'accessibility1'
  | 'accessibility2'
  | 'accessibility3'
  | 'accessibility4'
  | 'accessibility5'
  | 'large'
  | 'medium'
  | 'small'
  | 'xLarge'
  | 'xSmall'
  | 'xxLarge'
  | 'xxxLarge';
Swift
enum DynamicTypeSize

Pass a literal, or build one with SwiftUI.DynamicTypeSize from import { SwiftUI } from 'swiftui-react-native'.

Type properties

Overview

Read this value from the environment to adapt a layout to the text size someone chooses in system settings. The sizes are ordered, so you can compare them to find out how much room the text needs.

struct BatteryLabel: View {
    @Environment(\.dynamicTypeSize) private var dynamicTypeSize

    var body: some View {
        if dynamicTypeSize >= .accessibility1 {
            VStack {
                BatteryIcon()
                Text("Charging")
            }
        } else {
            HStack {
                BatteryIcon()
                Text("Charging")
            }
        }
    }
}

The five sizes whose names begin with accessibility are much larger than the rest. Check DynamicTypeSize.isAccessibilitySize when you want to change a layout for those sizes without comparing sizes yourself.

For more information, see doc://com.apple.documentation/design/human-interface-guidelines/typography in the Human Interface Guidelines.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Layout.