如何为一组UIControls设置单个VoiceOver

How to set single VoiceOver for group of UIControls

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?

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.

Awesome answer.