Add accessible labels, values, and hints
Annotate text and buttons with .accessibilityLabel, .accessibilityValue, and .accessibilityHint so assistive tech conveys meaning.
Example
Demo.swift
ContentView.swift
App.swift
import SwiftUI
struct A11yLabelsDemo: 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")
}
}
}
The example above shows a label, value, and hint for a control.
Leave a Reply