How to use decorative images to reduce screen reader clutter
How to use decorative images to reduce screen reader clutter êŽë š
Updated for Xcode 15
SwiftUI automatically uses the names of your images for screen reader labels, which is helpful if you have image names like âPhoto of Paul Hudsonâ or âHacking with Swift logo.â However, some images arenât meant to be read because they are merely decorative â they donât convey information that isnât already elsewhere on the screen, or are instead just there to make the user interface look more attractive.
If you create these images using something like Image("star")
the screen reader will read them out as part of its standard UI pass. A better idea is to create them using using the Image(decorative:)
initializer, which tells SwiftUI the image shouldnât be exposed to the screen reader:
Image(decorative: "star")
Once youâve built your user interface itâs worth doing a final check over using VoiceOver to make sure you have marked your images correctly â the last thing you want is the screen reader speaking out weird internal filenames that you thought were only used in your code!