Accessibility up to 11! LogoAccessibility up to 11! Logo - Dark ModeAccessibility up to 11!
  • Blog
  • #365DaysIOSAccessibility
  • Apps
  • About
  • Resources
  • RSS
#365DaysIOSAccessibility

Day 2

SwiftUI accessibility modifiers match UIKit

20 May 2022

Accessibility ModifiersSwiftUIUIAccessibilityUIKit

By

Daniel Devesa Derksen-Staats

SwiftUI has equivalent accessibility modifiers for some of UIAccessibility's properties in UIKit. Same basic concepts apply.

Label: https://developer.apple.com/documentation/swiftui/view/accessibilitylabel(:)-9ek2h

Value: https://developer.apple.com/documentation/swiftui/view/accessibilityvalue(:)-8esl7

Traits: https://developer.apple.com/documentation/swiftui/view/accessibilityaddtraits(:)

Hint: https://developer.apple.com/documentation/swiftui/view/accessibilityhint(:)-3i2vu

Some of you have asked me how you can support what I do. This would really help, and would be hugely appreciated:

  • Find these posts useful? Share them at work, on social media, or with anyone that might find them interesting. Let's spread the word!

  • Check out any of my apps or games: Xarra!, RetroRapid!, or Mestre!.

    • A download and a review go a long way. They're free by default. On the App Store, ratings and reviews really help more people discover them.

    • Finding any of them useful? If so, and if you can afford it, purchasing lifetime access to all features or subscribing lets me buy the coffee that keeps me caffeinated. Caffeine keeps me going to maintain the apps, bring in new features that I hope you'll love, and keep writing.

You may also find interesting...

Day 1

UIAccessibility: label, value, trait, and hint

UIAccessibility is the cornerstone of any accessible UIKit app. Among others, understanding what an accessibility label, value, trait or hint are, is key. This is an example of how they could be configured for a custom rating component.

GAADGAAD2022UIAccessibilityUIKitaccessibilityLabel

Day 110

Manage accessibility traits in SwiftUI

As with UIKit, in SwiftUI you can also add/remove a11y traits. But because of its declarative nature, you'll have to approach it in a slightly different way. A little nuance, but something that made me scratch my UIKit head when learning SwitUI.

SwiftUIUIKit

Day 108

Build adjustable controls in SwiftUI

In UIKit, to create an adjustable component we need to add the adjustable trait and override both accessibilityIncrement() and accessibilityDecrement(). In SwiftUI, everything you need is bundled in the accessibilityAdjustableAction(_:) modifier.

SwiftUIUIKitaccessibilityAdjustableActionadjustable

Content © Daniel Devesa Derksen-Staats on Accessibility up to 11! is licensed under CC BY 4.0. License details


← Day 3
Day 1 →

Created in Swift with Ignite.

Supporting Swift for Swifts