Accessibility in iOS 14 Widgets With SwiftUI

Accessibility in iOS 14 Widgets With SwiftUI

This summer, Apple announced widgets for iOS 14 that you can have on your home screen alongside your existing apps. Widgets help you to personalise the screen with glanceable relevant data upfront. Developers must use Apple's WidgetKit and declarative framework SwiftUI for creating the widgets on iOS 14.

Introduction

This summer, Apple announced widgets for iOS 14 that you can have on your home screen alongside your existing apps. Widgets help you to personalise the screen with glanceable relevant data upfront.

Developers must use Apple’s WidgetKit and declarative framework SwiftUI for creating the widgets on iOS 14.

Accessibility in SwiftUI

It’s refreshing to see how easy it is to make your application accessible using SwiftUI. Adding an accessibility label to a settings icon is as simple as:

.accessibilityLabel(“Settings“)

Developers can take advantage of the straightforward APIs and implement these in their apps.

And also widgets.

So let’s look at some of the topics of accessibility and how you can implement them in your widgets!

VoiceOver and Widgets

VoiceOver is a screen reader built into iOS that allows blind and low-vision users to use a touch screen by audibly describing elements of the screen as they pan or swipe around it.

I’ll focus on some general accessibility APIs that you can adapt to your apps for a great experience for VoiceOver users.

  • **accessibilityLabel(_:)**You’ll usually use this method for providing labels to images and logos. You may have the logo of your app on the widget, which you may want the user to hear, and not logo_image or something along that line.
Image("logo_image").accessibilityLabel(model.appName)
  • **accessibilityValue(_:)**If your widget has some value that is different from the label, you should use this method. For example, in a book-reading tracker widget, the number of books read, which will be dynamic, can be defined using this method.
Text("Number of books read")
  .accessibilityValue(“\(model.booksRead)“)
  • **accessibilityHint(_:)** The hint is for communicating the action after the user clicks on something. As it is either a widget with static data or deep links, I haven’t come across widgets even by Apple where they provide hints, as it is something not needed in this case.
  • **accessibilityAction(_:_:)**As mentioned above, an app’s action is either nothing for glanceable data or it directly opens the deep link, so a custom action may not be needed.
  • **accessibilityElement(children:)**This instance method is particularly useful when you may want to combine a lot of text to be read at once. For example, the Podcasts app combines the name of the podcast, author, data, and the description into one element.
VStack {
  Text("\(model.date)")
  Text(model.author)
  Text(model.title)
  Text(model.description)
}
.accessibilityElement(children: .combine)
  • **accessibilityHidden(_:)**There may be cases when you want to hide the image completely from VoiceOver to read the element. In this case, you should use this method. For example, in the Weather widget, the icon for describing the weather is not read out by the reader. Do note that Image also has an initialiser, where the readers skip reading the image element.
Image(decorative: model.imageName)
  • **accessibilityAddTraits(_:)**For best describing the accessibility element and its characteristics, this method is used. For example, you may have title text in your app, and for distinguishing it from other texts, you can use the isHeader type property for it.
VStack {
  Text("Gradient Game").accessibilityAddTraits(.isHeader)
  ForEach(model.histories, id: \.self) { history in
    HistoryView(history: history)
  }
}

Apart from that, to configure the widget using intents, the user may use a long double-press to edit the widget and open the configuration menu. In my general observation, the list in the menu has access to accessibility benefits natively.

For example, when providing a title in INObjectSection, it automatically configures it with the header trait.

accessibility swift swiftui programming ios

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Understanding Grids in SwiftUI for iOS 14

SwiftUI was announced at WWDC 2019 and it paved a way for declarative programming for building interfaces. SwiftUI Grid comes in two different flavours, which includes LazyVGrid and LazyHGrid. As the name suggest, LazyVGrid is a Grid that flows in vertical direction and the LazyHGrid flows in horizontal direction.

Swift Basic — Access Control

Do you understand what private, fileprivate, internal, public and open mean in Swift? It is useful when you are developing SDK / API !!!

Top Swift iOS App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

How To Stack Views & Use Modifiers Efficiently in SwiftUI

There are three built-in stacking views in SwiftUI; VStack, HStack, and ZStack. All three stacks are of type View. Stacks have alignment and content parameters.

SwiftUI Grids in iOS 14

SwiftUI was announced at WWDC 2019 and it paved a way for declarative programming for building interfaces. SwiftUI Grid comes in two different flavours, which includes LazyVGrid and LazyHGrid. As the name suggest, LazyVGrid is a Grid that flows in vertical direction and the LazyHGrid flows in horizontal direction