Created
April 26, 2022 17:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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