Course outline

iOS / Swift / Swift values and SwiftUI ownership / Lesson 7

SwiftUI images and accessible meaning

Display asset and system images while giving informational content and actions clear accessible meaning.

About 3 min readContent reviewed
On this page

Lesson goals

  • Distinguish asset images from system symbols.
  • Provide meaningful accessible descriptions.
  • Verify scaling and VoiceOver on a target.

Identify the image purpose

An image may convey information, decorate a view or identify an action. Decide its purpose before adding a label: informational content needs an equivalent description, while redundant decoration should not create repeated announcements. Use a native Button for an action rather than expecting an image alone to provide interaction semantics. Localize user-facing descriptions for supported languages.

Display an asset

This view displays a named asset with proportional scaling and an accessibility label. The host project must contain an image set named WorkshopDiagram; the lesson does not supply an asset. The example requires a SwiftUI application and compatible SDK. A production description should communicate the diagramโ€™s useful content, not merely repeat the word diagram.

swift SwiftUI view requiring a project asset
import SwiftUI
struct WorkshopImage: View {
    var body: some View {
        Image("WorkshopDiagram")
            .resizable()
            .scaledToFit()
            .accessibilityLabel("Workshop diagram")
    }
}
Expected output
A configured host displays the WorkshopDiagram asset.

The view loads a named asset, scales it to fit and supplies an accessible description.

Label an action

The second view uses a Label inside a Button, combining a visible title and system symbol. Its caller supplies the action; the view does not open a real help screen on its own. Check symbol availability for the deployment target and verify that the resulting accessible name and action are understandable without relying on the icon alone.

swift SwiftUI view fragment
import SwiftUI
struct HelpButton: View {
    var action: () -> Void
    var body: some View {
        Button(action: action) { Label("Help", systemImage: "questionmark.circle") }
    }
}
Expected output
A configured host shows a Help button.

The native button exposes a text-labeled action with a system symbol.

Check layout and content

Test the image within its real parent constraints, with large Dynamic Type and long localized text nearby. A fixed appearance in a preview is not proof that it fits all supported windows. Do not use an image description to expose private data that the current user may not access. If the content changes, keep its description synchronized with the actual image.

Verify on a target

Supply a synthetic asset and action in an isolated host, then inspect layout and VoiceOver output on the intended simulator or device. Test the action, a missing or unsuitable asset and a larger text setting. Record the SDK and target used. A Swift model test or code inspection alone cannot establish image rendering or assistive-technology behavior.

Common errors and fixes

The asset does not appear.

Why it happens
The named image set is missing from the target bundle.
How to fix it
Add the reviewed asset to the correct target.
Prevent it next time
Build the actual host with its asset catalog.

VoiceOver repeats the same information.

Why it happens
A decorative image duplicates adjacent accessible text.
How to fix it
Choose an appropriate accessible representation for the content.
Prevent it next time
Test the complete view with VoiceOver.

An icon action has no understandable name.

Why it happens
The image was used as a control without a clear label.
How to fix it
Use a labeled native button.
Prevent it next time
Verify the action without relying on visual recognition.

2 practice exercises

1. Why does WorkshopImage need an asset in the host?

Show worked solution

Image resolves a named asset from the application bundle. The code supplies the name but not the image set; the target must include a suitable asset.

2. Why pair a system symbol with Help text?

Show worked solution

The text communicates the action without requiring recognition of the icon. Verify the resulting accessible name and behavior on the target.

Key takeaways

  • Choose image semantics from its purpose.
  • Use native labeled controls for actions.
  • Test assets, scaling and VoiceOver in the host.

Official references