Supporting dynamic type for text is essential to make the app accessible. Making images accessible sometimes is out of the box(system images) and sometimes requires a bit of work.
Let’s explore some very common cases:
The first decision we have to take is to decide if the image is a UI decoration or it carries essential information. By default in SwiftUI the images are accessible so when the image is just decoration we should make it non accessible.
If the image is a system image:
1 |
Image(systemName: "figure.walk") |
then we can make it non accessible by using the following code:
1 2 |
Image(systemName: "figure.walk") .accessibility(hidden: true) |
If the image is custom image, the we can initialise the image as follows:
1 |
Image(decorative:"walk") |
Another thing to consider is when the text grows, the image has to grow also. This happens automatically for system images, but not for custom images and unlikely the UIKit here we don’t have the API to support it. So for the custom images we have to create our custom symbol by following the Apple’s instructions https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app.
Lastly when the image file is not readable or suitable for voice over, then we can add our own text for voice over:
1 |
Image("randomName", label: Text("walk")) |