Skip to content

Instantly share code, notes, and snippets.

@andresr-dev
Last active May 1, 2022 17:30
Show Gist options
  • Save andresr-dev/c0ed85b3d354f90445d6d7aa0577324b to your computer and use it in GitHub Desktop.
Save andresr-dev/c0ed85b3d354f90445d6d7aa0577324b to your computer and use it in GitHub Desktop.
This is an example of how you can support voice over accessibility in your applications.
import SwiftUI
struct AccessibilityExample: View {
var body: some View {
ZStack {
// Background
Image(decorative: "wood")
.resizable()
.ignoresSafeArea()
// Content layer
VStack(spacing: 20) {
VStack {
Text("Your score is")
Text("1000")
.font(.title)
}
.padding()
.background(.regularMaterial)
.cornerRadius(15)
.padding(.bottom)
.accessibilityElement(children: .ignore)
.accessibilityLabel("Your score is 1000")
Image(systemName: "heart")
.font(.largeTitle)
.padding()
.background(Circle().fill(.regularMaterial))
.onTapGesture {
// Do something
}
.accessibilityLabel("heart")
.accessibilityAddTraits(.isButton)
.accessibilityRemoveTraits(.isImage)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment