Skip to content

Instantly share code, notes, and snippets.

@mrhanlon
Last active March 12, 2024 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrhanlon/7f577c02de07ecc0ebf6b62c3e218a16 to your computer and use it in GitHub Desktop.
Save mrhanlon/7f577c02de07ecc0ebf6b62c3e218a16 to your computer and use it in GitHub Desktop.
Regarding [this module](https://www.hackingwithswift.com/books/ios-swiftui/hiding-and-grouping-accessibility-data) from 100 Days of Swift UI, it appears that when using `Image(decorative: "foo")` VoiceOver is disabled for the component even if accessibility label/traits are added.
struct ContentView: View {
let pictures = [
"ales-krivec-15949",
"galina-n-189483",
"kevin-horstmann-141705",
"nicolas-tissot-335096"
]
let labels = [
"Tulips",
"Frozen tree buds",
"Sunflowers",
"Fireworks",
]
@State private var selectedPicture = Int.random(in: 0...3)
var body: some View {
VStack {
Image(pictures[selectedPicture])
.resizable()
.scaledToFit()
.accessibilityLabel(labels[selectedPicture])
.padding(.vertical)
// won't work
Image(decorative: "galina-n-189483")
.resizable()
.frame(width: 200, height: 100)
.clipShape(.capsule)
.padding()
.onTapGesture {
selectedPicture = Int.random(in: 0...3)
}
.accessibilityLabel("Change image")
.accessibilityAddTraits(.isButton)
.accessibilityRemoveTraits(.isImage)
// works
Image("ales-krivec-15949")
.resizable()
.frame(width: 200, height: 100)
.clipShape(.capsule)
.padding()
.onTapGesture {
selectedPicture = Int.random(in: 0...3)
}
.accessibilityLabel("Change image")
.accessibilityAddTraits(.isButton)
.accessibilityRemoveTraits(.isImage)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment