thealienisreal
thealienisreal

Reputation: 292

How to get VoiceOver to announce section labels in iOS?

In the iPhone Weather App, when using VoiceOver, I noticed that tapping into a section for the first time, it will announce the section.

For example, in iOS 9, tapping on any item the middle strip for the first time will announce "Hourly forecasts" before continuing to describe the element you tapped on. Tapping anything else in the strip will not announce "hourly forecasts".

Tapping on anything on the bottom table, will announce "Daily forecasts" before continuing to describe the element you tapped on. Tapping anything else in this table will not prefix with "Daily Forecasts".

Is there a simple API to name sections of your app? Or do you have to do this manually by tracking the voiceover cursor and dynamically changing your label? (Does this even work? Can you change the accessibilityLabel after something is tapped but before it is read?)

Upvotes: 10

Views: 1295

Answers (2)

SHN
SHN

Reputation: 795

There are two approaches I guess:

  1. Subclassing the UITableViewCell and overriding the accessibilityLabel.

    - (NSString *) accessibilityLabel
    {
        NSString* voiceOverString;
        // append section title on voiceOverString and then the elements value
        return voiceOverString;
    }
    
  2. See this link from Apple docs: You can setAccessibilityLabel of the cell from cellForRowAtIndexPath. The example is for the weather app itself.

Upvotes: 3

Andrew Kirna
Andrew Kirna

Reputation: 1396

Is there a simple API to name sections of your app?

It seems like the most appropriate reference is Apple's Accessibility Programming Guide.

And its API, Apple's UIAccessibility Documentation.

Setting the shouldGroupAccessibilityChildren property seems like the best way to accomplish your goal. The linked API describes it as,

A Boolean value indicating whether VoiceOver should group together the elements that are children of the receiver, regardless of their positions on the screen. Setting the value of this property to YES on the parent view of the items in the vertical columns causes VoiceOver to respect the app’s grouping and navigate them correctly.

Things to keep in mind:

  1. Is the target element an accessibility element? (you can check using the isAccessibilityElement property; standard UIKit controls and views implement the UIAccessibility protocol by default)
    • If so, you just need to set its accessibility attributes
    • If not, you need to change its value, view.isAccessibilityElement = true
  2. The accessibilityLabel property identifies the element
  3. The accessibilityHint property describes the action triggered by an element
  4. You can set accessibility attributes in the storyboard
  5. Or, you can set accessibility attributes in the implementation of your view subclass

Upvotes: 0

Related Questions