SwiftUI Accessibility Read Value Controls

Main Idea

SwiftUI Accessibility Read Value Controls, we can dictate the gestures for incrementing and decrementing value

import SwiftUI
struct ContentView: View {
    @State private var value = 10
    
    var body: some View {
        VStack {
            Text("Value: \(value)")
            
            Button("Increment") {
                value += 1
            }
            
            Button("Decrement") {
                value -= 1
            }
        }
        .accessibilityElement()
        .accessibilityLabel("Value")
        .accessibilityValue(String(value))
        .accessibilityAdjustableAction { direction in
            switch direction {
            case.increment:
                value += 1
            
            case .decrement:
                value -= 1
            default:
                print("Not Handled.")
            }
        }
    }
}

Notes mentioning this note


Here are all the notes in this garden, along with their links, visualized as a graph.