0

I have a UIButton and a UILabel embedded in a UIStackView, which looks something like this in Interface Builder:

enter image description here

By setting the UIStackView's isAccessibilityElement and accessibilityLabel properties, I have been able to group the UIButton and UILabel into a single VoiceOver grouping, similar to this:

enter image description here

However with this configuration, the UIButton (gray circle in the image above) becomes untappable, rendering the control useless.

Is there a way to maintain this grouping while still allowing the UIButton to be tappable?

Marco
  • 6,692
  • 2
  • 27
  • 38
  • What did you do to group the button and the label? – David Rönnqvist Nov 01 '17 at 22:25
  • Hi @DavidRönnqvist, I've updated the question in answer to yours. Thanks. – Marco Nov 01 '17 at 22:35
  • 1
    @Marco : to complete the excellent answer of David Rônnqvist, take a look at http://a11y-guidelines.orange.com/mobile_EN/dev-ios.html#grouping-elements to get some code snippets (Objc + Swift) dealing with your question. – XLE_22 Mar 21 '19 at 12:27

1 Answers1

3

By default the accessibilityActivationPoint for an accessibility element is the midpoint of its frame. When the button and the label got grouped into a new element the midpoint of their combined frame is no longer in the bounds of the button.

You can fix this by overriding the stack view's accessibilityActivationPoint so that it returns the activation point of the button instead. Note that this property is in screen coordinates, so if the view moves on screen (for example scrolls) then it won't be enough to just set it once.


Also, for the grouped element to "behave" like a button to users of assistive technologies you should give it the accessibilityTraits of a button. A complete list of all can be found here.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205