What is Accessibility?
Accessibility in iOS allows users with hearing disabilities and visual impairments to access iOS and your application by supporting various features like Voice Control, VoiceOver, White on Black, Mono Audio, Speech to Text and so on.
More accessibility features are described in: Understanding Accessibility on iOS by Apple.
Why make use of Accessibility in my Application?
Here are the two main reasons:
One, it will enable more users to access your application and its features. Secondly, it is quite simple to implement.
How to: Use Accessibility features in iOS – Apple Support
Starting with VoiceOver in iOS
VoiceOver is Apple’s innovative screen-reading technology, which gives users control over their devices without having to see the screen. VoiceOver does this by acting as an intermediary between an application’s user interface and the user’s touch, providing audible descriptions of elements and actions in the application.
– Apple: Accessibility Programming Guide for iOS: Accessibility and VoiceOver
VoiceOver enables users with visual impairments use your application with the help of an audio guide which provides audio clues for using iOS applications.
Supporting VoiceOver in your Application
Enabling VoiceOver in your application is as easy as pie. All you need to do is specify the values for various accessibility attributes such as those below.
isAccessibilityElement: Is a boolean that specifies whether an UI element is visible to assistive technology. In other words if iOS should provide help for this element.
All controls and labels have this set to YES by default.
accessibilityLabel: this is a string that specifies the label of the UI element. This usually would be same as the label that is being displayed in the UI/screen.
accessibilityHint: this is a string that provides descriptive details about the accessibility element.
For instance a button might might have a description of what action is performed on clicking the button.
Below example shows setting accessibility values for a table cell “cell” which has a label called “textLabel”. UIAccessibility is an extension of NSObject and hence can be used on pretty much everything in cocoa.
let cellTextLabel : UILabel = cell.textLabel! cellTextLabel.text = NSLocalizedString("Create New Reminder", comment: "Creates New Remainder") cellTextLabel.isAccessibilityElement = true cellTextLabel.accessibilityLabel = NSLocalizedString("Create New Reminder", comment: "Creates New Remainder") cellTextLabel.accessibilityHint = NSLocalizedString("Select to create a New Reminder", comment: "Create New Reminder accessibility hint")
If you are not familiar with NSLocalizedString, do check out Internationalization and Localization in iOS.
accessibilityTraits: For custom UI in the application, we can also specify what is called as accessibilityTraits.
These will help describe the various functions of the UI element.
It has values like:
and so on.
In case you have added a custom item that also behaves as a button, add the button trait as below.
view.accessibilityTraits = (view.accessibilityTraits | UIAccessibilityTraitButton)
Note: UIAccessibilityTraits is a mask that combines all accessibility traits and hence, always add the new Accessibility trait to the existing list.
accessibilityValue: For UI elements that change their values like a UIPicker or a UISlider, you can set the current value to the accessibilityValue property whenever it gets updated so that it will be spoken by the VoiceOver.
UIAccessibilityAction Protocol: For complex actions associated with accessibility elements, there is a UIAccessibilityAction protocol which defines few methods for handling such scenarios when user double taps to select the action.
More information on this here:
UIAccessibilityContainer: These are essentially used when a single view contains multiple accessibility elements Or even when a view has small text elements or badges that are hard to individually select to have their own accessibility values.
Required for elements that aren’t views. For instance elements like drawing on a view.
It has a property accessibilityElements which is an Array which also means it is an ordered list. Hence, it can be used to contain multiple accessibility elements and VoiceOver will go over the elements in the same order as the elements in this list.
(This is helpful in cases where reading the labels in the order of their appearance is confusing or sometimes even incorrect.)
Lets suppose you have a view/cell as below:
The default sequence would read out in the below order.
Which of course doesn’t make sense for someone with visual impairment and can be corrected by adding the elements in the required order to the accessibilityElements property.
UIAccessibilityCustomAction: Custom actions allows users to provide custom actions to be performed on accessible objects. More details on this here.
Testing the Application for VoiceOver
1. On an iOS device: Using VoiceOver from settings.
On Device: Settings > General > Accessibility > VoiceOver: ON
Note that, once VoiceOver is ON, single tap does not open the application. Instead single tap highlights an accessibility element and reads over the accessibility label and hints on the element. You will have to double tap to select the item and double tapping can be done anywhere on the screen to select the highlighted item.
For more details on this refer to the guide below:
Apple: Test Accessibility on Your Device with VoiceOver
2. On iOS Simulator: Using Accessibility Inspector.
On Simulator: Settings > General > Accessibility > Accessibility Inspector: ON
Sample screenshot of above implementation:
The accessibility inspector on the simulator is displayed in a dialog as shown below and there are no audio clues as on an actual device. Hence, the application needs to be tested on a device to verify if is working as expected prior to shipping.
- Apple: Accessibility on iOS
- Apple: Accessibility Programming Guide for iOS
- Apple: Debug Accessibility in iOS Simulator with the Accessibility Inspector
- Use Your Loaf: VoiceOver Accessibility (Objective C tutorial)