NEW BOOK! SwiftUI Fundamentals: The essential guide to SwiftUI core concepts and APIs. Learn more ...NEW BOOK! SwiftUI Fundamentals:Master SwiftUI core concepts and APIs. Learn more...
Quick Tip Icon
Quick Tip

Automatic image accessibility labels from localized strings in SwiftUI

When an image is loaded by name using the Image(_:) initializer in SwiftUI, VoiceOver uses the image name itself as the default accessibility label.

For example, if we have a custom image in the asset catalog named person.bicycle, VoiceOver will read "person bicycle" unless a custom label is explicitly provided.

// VoiceOver reads "person bicycle" by default
Image("person.bicycle")

However, if a localized string is defined for the image name, either in a Localizable.strings file or a string catalog, SwiftUI will automatically use the localized value as the accessibility label, without requiring the accessibilityLabel() modifier.

String catalog entry in Xcode showing a localized value for the image name person.bicycle

In our example, using "person.bicycle" = "Person on a bicycle" for the English localization causes VoiceOver to read "Person on a bicycle" when the image is focused, with no additional code changes needed.

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

Deepen your understanding of SwiftUI!$35

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentalsby Natalia Panferova

  • Explore the key APIs and design patterns that form the foundation of SwiftUI
  • Develop a deep, practical understanding of how SwiftUI works under the hood
  • Learn from a former Apple engineer who worked on widely used SwiftUI APIs

Deepen your understanding of SwiftUI!

The essential guide to SwiftUI core concepts and APIs

SwiftUI Fundamentals by Natalia Panferova book coverSwiftUI Fundamentals by Natalia Panferova book cover

SwiftUI Fundamentals

by Natalia Panferova

$35