0

Using VoiceOver in iOS, when looking at something like a segmented controller, VoiceOver reads the segments and their index, i.e. “Selected: Something: 2 of 4”.

I have a custom UIView container which holds a few buttons, and I’d like to replicate that “2 of 4” behaviour when swiping through the buttons in the container.

I’d ideally like to do this without creating a custom UIView subclass, if possible. Can that be achieved?

Luke
  • 9,512
  • 15
  • 82
  • 146

2 Answers2

1

You can achieve this by setting the one of the following accessibilityLabel, accessibilityValue, accessibilityHint and accessibilityTrait.

Assuming the button in question has the text is "Blue OK", and the extra text you want to be read is "2 out of 4"

  • By default VoiceOver will read:

"Blue OK" - SHORT PAUSE - "Button"


  • Setting the accessibilityLabel to "2 out of 4" will result in:

"2 out of 4" - SHORT PAUSE - "Button"


  • Setting the accessibilityValue to "2 out of 4" will result in:

"Blue OK" - SHORT PAUSE - "2 out of 4" - SHORT PAUSE - "Button"


  • Setting the accessibilityHint to "2 out of 4" will result in:

"Blue OK" - SHORT PAUSE - "Button" - LONG PAUSE - "2 out of 4"

Note that in this case "2 out of 4" will not get read with a 2 finger swipe down


VoiceOver will announce the object being selected if the button.selected flag is set to YES by setting a Trait to it. If you want to add it explicitly to an object that does not support the selected property, you can add the trait yourself:

//can concatenate multiples ones like so UIAccessibilityTraitButton | UIAccessibilityTraitSelected
mybutton.accessibilityTraits = UIAccessibilityTraitSelected; 

This trait gets read the same place where the "Button" gets read in the examples above:

"Blue OK" - SHORT PAUSE - "Button, Selected"

If you want the order of wording to be different then you'll need to mix and match the values of accessibilityLabel, accessibilityValue, accessibilityHint and accessibilityTrait until you get the exact wording you're looking for.

Feras Arabiat
  • 826
  • 6
  • 11
0

Append the button index to the item's accessibilityLabel. There's no magic, here. This context isn't necessarily helpful to users of other accessibility clients, including Switch Control, but there's no other way to reproduce internal VoiceOver behavior than changing UIAccessibility properties.

Justin
  • 20,509
  • 6
  • 47
  • 58