Skip to content

Instantly share code, notes, and snippets.

@andresr-dev
Created April 26, 2022 17:18
Show Gist options
  • Select an option

  • Save andresr-dev/8390419fdd70125d54faed881117969c to your computer and use it in GitHub Desktop.

Select an option

Save andresr-dev/8390419fdd70125d54faed881117969c to your computer and use it in GitHub Desktop.
This is an example of how you can modify values using accessibility.
import SwiftUI
struct AccessibilityValueExample: View {
@State private var value = 10
var body: some View {
VStack(spacing: 20) {
Text("Value: \(value)")
Button("Increment") {
value += 1
}
Button("Decrement") {
value -= 1
}
}
// This is .accessibilityElement(children: .ignore) by default
.accessibilityElement()
.accessibilityLabel("Value")
.accessibilityValue(String(value))
.accessibilityAdjustableAction { direction in
switch direction {
case .increment:
value += 1
case .decrement:
value -= 1
default:
print("Not handled")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment