How to use the .dynamicTypeSize modifier in SwiftUI
Dynamic Type allows users to set their preferred text size on the device they are using. This is great for accessibility, but without proper planning parts of your app can render useless if larger text sizes are not accounted for.
In cases where your design does not allow for larger text sizes, the .dynamicTypeSize
modifier can be used to set an upper limit.
Usage
You can use the modifier with either a specific Dynamic Type size, or a range of sizes.
VStack {
Text("Small text")
.dynamicTypeSize(.small)
Text("Text scales to accessibility1 size")
.dynamicTypeSize(...DynamicTypeSize.accessibility1)
Text("Text can scale between small and large")
.dynamicTypeSize(.small ... .large)
}