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

Image accessibility labels from Localizable.strings files

I recently discovered that if we add an image name to the Localizable.strings file in a SwiftUI project, SwiftUI will automatically use the localized string as the image accessibility label.

For example, we might have a custom image in the Assets catalog called person.bicycle. When it's used in a SwiftUI Image view Voice Over will read "person bicycle" when the user is focused on the image.

// Voice over reads "person bicycle" by default
Image("person.bicycle")

If we add the image name to the Localizable.strings file to provide a better accessibility label and to localize it, SwiftUI will use the localization automatically.

// Inside a Localizable.strings file
"person.bicycle" = "Person on a bicycle";

Voice Over will now read "Person on a bicycle" when the image is focused. We don't even have to apply the accessibilityLabel() modifier to the Image view.

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