Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS VoiceOver reading accessibilityIdentifier instead of accessibilityLabel

VoiceOver should read the accessibilityLabel property of any accessibility element on the screen. I have a UIImageView called mediaImageView, the code below sets up accessibility on this view and is called in awakeFromNib in a UITableViewCell subclass.

Rather than reading image, VoiceOver reads articleMediaCell_image which is the accessibilityIdentifier. Can anyone explain why this this could be happening?

(testing on device with iOS 13.3, issue happens whether or not custom actions are set)

    mediaImageView.isAccessibilityElement = true
    mediaImageView.accessibilityIdentifier = "articleMediaCell_image"
    mediaImageView.accessibilityLabel = "image"

    mediaImageView.accessibilityCustomActions = [
        UIAccessibilityCustomAction(
            name: "expand to fullscreen",
            target: self,
            selector: #selector(imageTapped)
        )
    ]
like image 719
Ben Sullivan Avatar asked Apr 15 '20 13:04

Ben Sullivan


People also ask

What is accessibility identifier IOS?

An identifier can be used to uniquely identify an element in the scripts you write using the UI Automation interfaces. Using an identifier allows you to avoid inappropriately setting or accessing an element's accessibility label. Current page is accessibilityIdentifier. Apple.

What is accessibilityLabel?

accessibilityLabel ​ When a view is marked as accessible, it is a good practice to set an accessibilityLabel on the view, so that people who use VoiceOver know what element they have selected. VoiceOver will read this string when a user selects the associated element.

How do I support VoiceOver in IOS?

By using your app with VoiceOver on, you can establish a baseline of its accessibility. To start auditing, choose Settings > Accessibility > VoiceOver, and enable VoiceOver. Then, open your app and use the specified action whenever you want to test VoiceOver.

What is VoiceOver accessibility?

TalkBack is the Google screen reader included on Android devices. TalkBack gives you spoken feedback so that you can use your device without looking at the screen. You can drag one finger around the screen and TalkBack announces the icons, buttons, and other items as you drag your finger over them.

What is an iOS accessibility tutorial?

In this iOS accessibility tutorial, you’ll transform an existing app to make it more accessible for people with visual disabilities. In the process, you’ll learn how to: Use VoiceOver. Check your app with the Accessibility Inspector.

How does voiceover audit the Accessibility elements?

As you scroll through the different accessibility elements, VoiceOver reads a full description of each cell, including the difficulty level. Every time you expose a new accessibility element, as you did here with the difficulty level, you should run the audit again.

How to make your iOS app accessible for people with disabilities?

In this iOS accessibility tutorial, you’ll transform an existing app to make it more accessible for people with visual disabilities. In the process, you’ll learn how to: Use VoiceOver. Check your app with the Accessibility Inspector. Implement accessibility elements with UIKit. Build a better user experience for people with disabilities.

How do I use the Accessibility Inspector in Xcode?

First, open it in the Xcode menu by navigating to Xcode ▸ Open Developer Tool ▸ Accessibility Inspector. The target chooser lets you pick which device you’d like to inspect. This could be your MacBook Pro, an iOS device or your simulator. Live previews of accessibility elements let you test right in the simulator.


Video Answer


2 Answers

This happens due to the fact that you have set the trait (image) of the control type as the value for accessibilityLabel here:

mediaImageView.accessibilityLabel = "image"
/*
This won't work, because iOS already knows that this is an image from the element's traits.
Due to this, the redundant value is ignored and the voiceover falls back to reading the `accessibilityIdentifier`.
*/

Use any value - "media" for example - that is other than the trait of the object, because the voiceover will read the accessibility label value followed by the trait of the control type like so: "Media Image".

mediaImageView.accessibilityLabel = "media" /* This will work */

Excerpt from accessibilityLabel Apple Documentation:

Note that the label never includes the control type (such as button) because the traits of the accessibility element contain that information.

like image 64
badhanganesh Avatar answered Sep 20 '22 17:09

badhanganesh


Set the accessibilityTraits of your mediaImageView to UIAccessibilityTraits.button.

mediaImageView.accessibilityTraits = UIAccessibilityTraits.button

like image 34
Daniel Storm Avatar answered Sep 19 '22 17:09

Daniel Storm