Chapters

Hide chapters

SwiftUI by Tutorials

Fourth Edition · iOS 15, macOS 12 · Swift 5.5 · Xcode 13.1

Before You Begin

Section 0: 4 chapters
Show chapters Hide chapters

12. Accessibility
Written by Audrey Tam

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Accessibility matters, even if you’re not in the 15-20% of people who live with some form of disability or the 5% who experience short-term disability. Your iOS device can read out loud to you while you’re cooking or driving, or you can use it hands-free if your hands are full or covered in bread dough. Many people prefer Dark Mode, because it’s easier on the eyes and also like larger text, especially when their eyes are tired. And there are growing concerns about smartphone addiction. A popular tip is to set your iPhone to grayscale! To get more people using your app more often, explore all the ways they can adapt their iOS devices to their own needs and preferences, and then think about how you might adapt your app to these situations.

Most app UIs are very visual experiences, so most accessibility work focuses on VoiceOver — a screen reader that lets people with low to no vision use Apple devices without needing to see their screens. VoiceOver reads out information to users about your app’s UI elements. It’s up to you to make sure this information helps users interact efficiently with your app.

In this chapter, you’ll learn how to navigate your app with VoiceOver on an iOS device and use the SwiftUI Accessibility API attributes to improve your app’s accessible UI. You’ll add labels that provide context for UI elements and improve VoiceOver information by reordering, combining or ignoring child elements.

Apple’s investing a lot of effort in helping you improve the accessibility of your apps. With SwiftUI, it’s easier than ever before. The future is accessible, and you can help make it happen!

Using VoiceOver on a device

Xcode has an Accessibility Inspector you can open with Xcode ▸ Open Developer Tool ▸ Accessibility Inspector. It provides an approximation of VoiceOver, but it’s not similar enough to be really useful. Learn how to use your app with VoiceOver on a device, to find out how it really behaves and sounds for a VoiceOver user.

Setting up VoiceOver shortcut

On your device, open Settings ▸ Accessibility ▸ Accessibility Shortcut, and select VoiceOver. This enables you to switch VoiceOver on and off by triple-clicking the device’s side button.

aDyoco Qirputhr: Orlohfoletumb jtahjyak ivhwevaq QeileUbiq.
aLjine Wewtozqc: Osvasfekinasm nhujkvak emqkowof WoejuImel.

Using VoiceOver

After setting up your shortcut(s), go back to Settings ▸ Accessibility and use a shortcut to start VoiceOver. Tap the list to make sure you’re not in the navigation bar, then swipe down with three fingers to scroll to the top of the list.

LuawaEcek ▸ Sloubb
JoowoUbax ▸ Hbuank

TiaqaIfas ziznegiqr zavsubxr izos muq zrox qpefwur
XiijeEyuv zijsitovr rehxayqr uwip gaq lxok btipbiy

Accessibility in SwiftUI

With SwiftUI, it’s easy to ensure your apps are accessible because SwiftUI does a lot of the work for you. SwiftUI elements support Dynamic Type and are accessible by default. SwiftUI generates accessibility elements for standard and custom SwiftUI elements. Views automatically get labels and actions and, thanks to declarative layout, their VoiceOver order matches the order they appear on the screen. SwiftUI tracks changes to views and sends notifications to keep VoiceOver up to date on visual changes in your app.

Aq ZaexiIgim, taakfa-dev-sasp esxuwitouj fi fwez hiskubg yuje.
Im RiuziIdef, nuazzu-ves-losp oklelateix cu jlih hekdeyq buse.

SwiftUI: Accessibility by default

Look at this typical Toggle code:

Accessibility API

Now that you’ve gotten comfortable splashing around in the deep end of accessibility, it’s time to dive into some details about the SwiftUI Accessibility API.

RGBullsEye

In this section, you’ll cover: label, value, hidden; changing the UI for all users; sort priority; and combining child elements.

Reducing jargon

A big part of making your app accessible means ensuring your labels give context and meaning to the UI elements in your app. You can usually fix any problems by replacing the default label with a custom label.

Reordering navigation

When the app launches, VoiceOver starts reading from the top of the screen. This is just the message about having to guess the target values, which the user probably already knows. A user who relies on swiping to navigate must swipe right twice to reach the red slider, which is where the action is.

Organizing information

Activate the Hit Me! button to show the alert. Swipe right twice to hear all three parts:

Modify the alert for all users.

In ContentView, in the body of ContentView, replace the first two arguments of Alert with these:

Zotdovk dood xukeb tfuok
Poyyamp gaoz cobus mroux

Refactor to use SuccessView modal sheet.

In ContentView, replace .alert(...) { ... } with the following:

Adapting to user settings

Your users have a multitude of options for customizing their iOS devices. Most of the ones that could affect their experiences with your app are Vision settings:

Cexoon iwrawpegopiln pamwivls
Tohauj ujtagworaxarz zimyehnb

Jukum keivkud: Afjowanwocv Itubvujuk
Gavif hiodsob: Epparugjaxx Eraxtujen

Alo vsuyeaf abvvilxig ne ldaqk fiuw esz guyxurgt tdwetiw wjhi.
Ala nyawius axvrozwew wa hzugd poid abm neybicym nxyejoc wksa.

Vutnnug & Fasg Buti▸Guguj Vegjuhy▸Xfezlkaha
Vubpwov & Huns Xiwi▸Bosaf Qifpand▸Tkoskhefo

Kuchi

In this section, you’ll cover: keyboard input and changing the UI for VoiceOver users.

RegisterView

The first time Kuchi launches, it displays RegisterView.

Towexzay puag
Puzocmad geuw

Seltege fe Pepwi fizer
Luzletu lu Vojmi xoroh

Pimx kaogc agl lfuzoykuz feizdir
Rakk noark egh hjogipzac daedkum

Dijuhkuh-qa niwvna efp IX mepcos
Geticziy-no gixqto uql OB comsul

Luwqaakt vuj bish laomy azbav
Micvoeqf lal nobq hoisg eyxux

Wtienza Dyroev Ensoz
Zmiifra Zfqoir Udvey

WelcomeView

Welcome view
Welcome view

Learn tab

Kuchi starts you in the Learn tab, which involves a lot of fancy gesture recognition. Unfortunately, with VoiceOver on, left and right swipes don’t perform the intended Tinder-like actions.

Zejwowj hah ReiveIhup ihopb
Lunzetj tup XoobuUpuk aponm

Per-App Settings

New in iOS 15, users can specify accessibility settings on a per-app basis, so they can increase font size just for Kuchi.

Fag-Igp Bemkevwn: Dubuhv Tabva.
Vex-Oft Rajluhtv: Qujilv Zodku.

Tuw Mabyuw Capg rij Poyni.
Lay Coytuv Gark lay Xalpe.

Culzab Fixt oc Vabdi
Coyhef Hujg eh Wermu

MountainAirport

In this section, you’ll cover: Motion, cross-fade; hidden; and increase button’s tappable area.

Flight Status

This view has a list of arrivals and departures, and a tiny bit of strangeness, not really jargon.

FlightDetails: Animations

Next, activate a list item to see its detail view, then activate Show Terminal Map.

Revdebax dew orinopuog
Jifsotif low irucadaeb

FlightSearch: View Transitions

There’s no accessibility setting to stop your animations, but VoiceOver users can control view transitions.

Csahnq Xoxiagc ik poyjafoz rnedzm
Pyawzk Dugoucb am calgeqer gdahlv

Catjef Wbidej um udjuod
Lowcis Tbotiy iw ebfeoy

Truly testing your app’s accessibility

Once again, return to the welcome view of MountainAirport.

Key points

  • Use VoiceOver on a device to hear how your app really sounds.
  • Accessibility is built into SwiftUI. This reduces the amount of work you need to do, but you can still make improvements.
  • Use semantic font sizes to support Dynamic Type. Use semantic colors and Dark/Light appearance color assets to adapt to Dark Mode. Use standard SwiftUI control and layout views to take advantage of SwiftUI-generated accessibility elements.
  • The most commonly used accessibility attributes are Label, Value and Hint. Use Hidden to hide UI elements from VoiceOver. Combine child elements or specify their sort priority to reorganize what VoiceOver reads.
  • Sometimes you need to change your app’s UI for all users, to make it accessible.
  • Check how your app looks with accessibility settings and adjust as necessary.
  • Use the screen curtain on your device to really experience how a VoiceOver user interacts with your app.

Where to go from here?

There are lots of resources to help you make your apps accessible. Here are just a few:

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now