Skip to content
Prepare to Grow

SwiftUI Fundamentals

Accessibility, Adaptive Layouts, and Mini Project

Build and review a complete SwiftUI learning app that adapts across devices, input methods, text sizes, and assistive technologies.

Intermediate6 min read2 guided activities

Before you begin

What you will understand

  • Create meaningful accessibility labels, values, traits, and actions.
  • Support Dynamic Type, contrast, reduced motion, and flexible layouts.
  • Combine module skills into a small multi-screen app.
  • Review the result with a practical quality checklist.
01

Learning stage

Concept Explanation

Accessibility begins with semantic structure. Native controls already communicate roles and interaction. Custom compositions may need children combined, decorative images hidden, or labels and values added so the spoken interface conveys the same meaning as the visual one. An accessibility label names an element; a value communicates its current state; a hint explains a non-obvious result sparingly.

Adaptive design responds to available space and user settings rather than detecting one device model. Support Dynamic Type, sufficient contrast, VoiceOver order, Reduce Motion, button shapes, localization, keyboard input, and different window widths. Use flexible layout first and introduce ViewThatFits or size-class choices when content genuinely needs another arrangement.

The mini project is a learning tracker with a lesson list, detail navigation, completion state, search, an editor sheet, async loading simulation, animation, and accessible progress. Build it in vertical slices: model and sample data, list states, navigation and detail, editing, async behavior, then accessibility and adaptive review.

  • Label: concise identity of an accessible element.
  • Value: current state such as progress or selection.
  • Trait/action: role and operations available to assistive technology.
  • Dynamic Type: user-selected scalable text sizes.
  • Adaptive layout: responds to content, space, locale, and interaction settings.
02

Learning stage

Syntax & Examples

The progress component preserves the visual design while presenting one concise, actionable accessibility element.

AccessibleProgress.swiftswift
import SwiftUI

struct AccessibleProgress: View {
  let completed: Int
  let total: Int

  private var fraction: Double {
    total == 0 ? 0 : Double(completed) / Double(total)
  }

  var body: some View {
    ViewThatFits(in: .horizontal) {
      HStack {
        Text("Course progress")
        Spacer()
        ProgressView(value: fraction) { EmptyView() }
          .frame(maxWidth: 180)
        Text("(completed) of (total)")
      }

      VStack(alignment: .leading, spacing: 8) {
        Text("Course progress")
        ProgressView(value: fraction)
        Text("(completed) of (total)")
      }
    }
    .accessibilityElement(children: .ignore)
    .accessibilityLabel("Course progress")
    .accessibilityValue("(completed) of (total) lessons complete")
  }
}
The layout changes when horizontal space is insufficient, while assistive technology receives one useful label and value instead of fragmented repeated text.
03

Learning stage

Real-World Usage

Connect the SwiftUI concept to complete, maintainable application features.

  • Support VoiceOver, Switch Control, keyboard navigation, and larger text.
  • Build interfaces that work in portrait, landscape, split view, and different Apple platforms.
  • Review contrast, hit targets, content order, and motion preferences before release.
  • Use previews and accessibility tools to inspect multiple representative states.
04

Learning stage

Common Mistakes

Identify patterns that weaken ownership, identity, adaptation, accessibility, or user experience.

  • Adding accessibility labels that repeat useful visible text without improving meaning.
  • Hiding interactive children inside one inaccessible combined element.
  • Using only color to communicate status.
  • Fixing text sizes or row heights so larger content clips.
  • Treating iPad as a larger fixed-width iPhone.
  • Saving accessibility review until after architecture and layout are difficult to change.
05

Learning stage

Practice Exercises

Build the behavior in a small Xcode project and review it in multiple states.

Activity 1

Build the learning tracker

Create the mini app with identified lesson models, observable shared state, search, list states, NavigationStack detail, completion binding, an editor sheet, async loading, and one purposeful animation.

Hint: Build one working vertical slice at a time and keep external services replaceable with sample implementations.

Activity 2

Perform an accessibility and adaptation audit

Test the project with VoiceOver, an accessibility text size, Reduce Motion, narrow and wide windows, increased contrast, and a long translated string. Record and fix at least five issues.

Hint: Verify task completion, not only whether every element can receive focus.

06

Learning stage

Knowledge Check

Answer each question before revealing the explanation.

QUESTION 1

What is the difference between an accessibility label and value?

  1. A.The label names the element; the value describes its current state
  2. B.They are always identical
  3. C.The value performs navigation
  4. D.The label controls layout
Reveal answer

The label names the element; the value describes its current state

For progress, the label might be “Course progress” and the value “6 of 10 lessons complete.”

QUESTION 2

What should drive an adaptive SwiftUI layout?

Reveal answer

The available space, content, and user settings—not a hard-coded device model.

Windows resize, text grows, and localization changes content even on the same hardware.

07

Learning stage

Interview Preparation

Explain the design in terms of data flow, identity, lifecycle, platform behavior, and trade-offs.

How do you approach accessibility in a SwiftUI feature?

Short answer: Start with semantic native controls, flexible content, and real task-based testing with accessibility settings and assistive technologies.

Explore the detailed answer

I make the hierarchy meaningful first, then add labels, values, traits, grouping, or actions only where the default semantics are insufficient. I test Dynamic Type, VoiceOver order and actions, contrast, Reduce Motion, localization, and multiple widths. I verify that a user can complete the feature, not merely that elements are announced.

Possible follow-ups

  • • When should children be combined?
  • • How does ViewThatFits help adaptation?
08

Learning stage

Key Takeaways

A SwiftUI interface is complete only when people can understand and operate it across content sizes, windows, languages, and assistive technologies. The mini project turns isolated APIs into one coherent, reviewable feature.

  • Prefer semantic native controls and hierarchy.
  • Labels identify; values communicate current state.
  • Adapt to content and space rather than device names.
  • Test Dynamic Type, VoiceOver, contrast, motion, and localization.
  • Integrate state, navigation, presentation, async work, and accessibility in one vertical feature.