Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Swift Basics

Swift HOME Swift Intro Swift Get Started Swift Syntax Swift Statements Swift Output Swift Comments Swift Variables Swift Data Types Swift Type Casting Swift Operators Swift Strings Swift Arrays Swift Ranges Swift If...Else Swift Switch Swift While Loop Swift For Loop Swift Break/Continue Swift Collections

Swift Types & Functions

Swift Functions Swift Optionals Swift Enums & Patterns Swift Closures Tuples & Type Aliases

Swift Object Model

Swift OOP Swift Inheritance Swift Polymorphism Swift Protocols Swift Generics Swift Extensions Access Control Initializers Deinitializers Value Semantics & COW Equatable & Comparable

Swift Robustness & Async

Swift Error Handling Swift Concurrency Swift Memory

Swift Tooling

Swift Package Manager

SwiftUI Basics

SwiftUI Intro iOS Project Setup SwiftUI Layout SwiftUI Navigation SwiftUI Data Flow SwiftUI Lists & Forms SwiftUI Animations SwiftUI Gestures SwiftUI Modifiers & ViewBuilder SwiftUI Previews SwiftUI Accessibility SwiftUI Styling & Theming

SwiftUI Data & Architecture

Networking Persistence Persistence (Core Data) MVVM Architecture AppStorage & SceneStorage Testing SwiftUI

iOS Capabilities

Privacy & Permissions Push Notifications Widgets & Extensions Background Work Core Location App Clips Keychain Basics CloudKit File System Background URLSession MapKit

iOS Quality & Compliance

Localization Accessibility App Privacy In-App Purchases Analytics & Reporting Testing with XCTest

iOS Release & Distribution

Assets & App Icons Signing & Distribution TestFlight & App Store Ship Your First App

Swift Exercises

Swift Exercises Swift Quiz

Accessibility


Accessibility

Label controls, support Dynamic Type and contrast, and test with VoiceOver to ensure inclusive experiences.


VoiceOver and Labels

All interactive elements must be perceivable to assistive technologies.

Provide meaningful labels and hints.

Example

import SwiftUI

struct ContentView: View {
  @State private var count = 0
  var body: some View {
    VStack(spacing: 12) {
      Text("Count: \(count)")
        .accessibilityLabel("Current count")
        .accessibilityValue("\(count)")
      Button("Increment") { count += 1 }
        .accessibilityHint("Increases the count by one")
    }
    .padding()
  }
}

In this example, the count is perceivable through both label and value.


Dynamic Type and Contrast

Use system text styles (e.g., .font(.body)) and check color contrast.

Respect reduced motion and increased contrast settings.

Tip: Test with VoiceOver, Larger Text, Bold Text, and different Appearance (Light/Dark).

Use the Accessibility Inspector in Xcode.


Semantics & Traits

Expose clear semantics and traits so assistive tech understands your UI.

Example

import SwiftUI

struct PlanBadge: View {
  var body: some View {
    VStack {
      Image(systemName: "star.fill")
        .foregroundStyle(.yellow)
        .accessibilityLabel("Favorite")
        .accessibilityAddTraits(.isImage)
      Text("Premium plan")
    }
    // Read as one element: "Favorite, Premium plan"
    .accessibilityElement(children: .combine)
  }
}

In the example above, the image is exposed as an image and the text as a label.



Focus, Order & Grouping

Control reading order and group related elements.

Example

import SwiftUI

struct TotalRow: View {
  var total: Double
  var body: some View {
    HStack {
      Text("Total")
        .accessibilitySortPriority(2)
      Text(total, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
        .accessibilitySortPriority(1)
    }
    // Alternatively, combine for a single announcement
    // .accessibilityElement(children: .combine)
  }
}

In the example above, the total is read as one element.


Custom Actions

Expose adjustable and named actions to VoiceOver users.

Example

import SwiftUI

struct QuantityStepper: View {
  @State private var qty = 1
  var body: some View {
    Stepper("Quantity: \(qty)", value: $qty)
      .accessibilityValue("\(qty)")
      .accessibilityAdjustableAction { direction in
        switch direction {
        case .increment: qty += 1
        case .decrement: qty = max(0, qty - 1)
        default: break
        }
      }
      .accessibilityAction(named: Text("Reset")) { qty = 1 }
  }
}

In the example above, the stepper has adjustable actions and a named action.

Testing checklist: Verify label, value, hint, traits; reading order; adjustable actions; Dynamic Type; dark/light contrast; and Reduced Motion.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.