DynamicTypeSize
A Dynamic Type size, which specifies how large scalable content should be.
Declaration
enum DynamicTypeSizeOverview
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 isAccessibilitySize when you want to change a layout for those sizes without comparing sizes yourself.
For more information, see Typography in the Human Interface Guidelines.
Topics
Getting type sizes
DynamicTypeSize.xSmallDynamicTypeSize.smallDynamicTypeSize.mediumDynamicTypeSize.largeDynamicTypeSize.xLargeDynamicTypeSize.xxLargeDynamicTypeSize.xxxLarge
Getting accessibility type sizes
DynamicTypeSize.accessibility1DynamicTypeSize.accessibility2DynamicTypeSize.accessibility3DynamicTypeSize.accessibility4DynamicTypeSize.accessibility5isAccessibilitySize