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

Demo.swift

ContentView.swift

App.swift

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")
}
} }

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

Demo.swift

ContentView.swift

App.swift

import SwiftUI

struct Badge: View {
  var body: some View {
VStack {
  Image(systemName: "star.fill")
  Text("Premium plan")
}
.accessibilityElement(children: .combine)
} }

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *