SwiftUI Accessibility Dynamic Type
SwiftUI Accessibility Dynamic Type
Respect user font size preferences with Dynamic Type and test scaling in previews.
Scale text with Dynamic Type
Allow text to scale across accessibility sizes and preview larger sizes to verify readability.
Example
import SwiftUI
struct DynamicTypeDemo: View {
var body: some View {
VStack(spacing: 8) {
Text("Title").font(.title)
Text("Body text that scales with accessibility settings.")
}
.padding()
.dynamicTypeSize(.accessibility2 ... .xxxLarge)
}
}
import SwiftUI
struct ContentView: View {
var body: some View { DynamicTypeDemo() }
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup { ContentView() }
}
}
The example above shows text that scales with accessibility settings.