SwiftUI Accessibility
SwiftUI Accessibility
Label controls, expose values and hints, and support Dynamic Type and VoiceOver in SwiftUI.
Labels & Values
Provide assistive technologies with descriptive labels, values, and hints so controls are clear and usable.
Example
import SwiftUI
struct A11yDemo: View {
@State private var count = 0
var body: some View {
VStack(spacing: 12) {
Text("Count: \(count)")
.accessibilityLabel("Current count")
.accessibilityValue("\(count)")
Button("Increment") { count += 1 }
.accessibilityHint("Increases the count by one")
}
}
}
import SwiftUI
struct ContentView: View {
var body: some View { A11yDemo() }
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup { ContentView() }
}
}
The example above shows a label, value, and hint for a control.
Grouping
Combine related views into one accessibility element so VoiceOver reads them together as a single item.
Example
import SwiftUI
struct Badge: View {
var body: some View {
VStack {
Image(systemName: "star.fill")
Text("Premium plan")
}
.accessibilityElement(children: .combine)
}
}
import SwiftUI
struct ContentView: View {
var body: some View { Badge() }
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup { ContentView() }
}
}
The example above shows a badge with a combined accessibility element.