Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you exclude a UIButton from VoiceOver?

I have a UIButton that is sometimes blank (no text or image). When it is blank, I want VoiceOver to skip over it. I've tried the following things, but none of them do the job -- the button still gets highlighted as the user swipes through the views:

  • Set the button and all of its subviews' .accessibilityTraits to UIAcessibilityTraitNotEnabled. This prevents VoiceOver from saying anything when the button is selected, but it still allows the button to be selectable by VoiceOver.

  • Disable the button (I verified that the button is disabled in the Debug View Hierarchy view). The button remains selectable by VoiceOver.

Anybody know how to make VoiceOver skip over / ignore a UIButton completely?

like image 237
Trevor Alyn Avatar asked Jan 22 '15 16:01

Trevor Alyn


Video Answer


2 Answers

Try the following:

someButton.isAccessibilityElement = NO;

This tells the button that it isn't an accessible element. This should prevent voice-over from stopping at the button.

like image 58
rmaddy Avatar answered Oct 09 '22 22:10

rmaddy


Swift 4

This didn't work for me:

someButton.isAccessibilityElement = false 

This did work:

someButton.accessibilityElementsHidden = true
like image 22
Mukesh Chapagain Avatar answered Oct 09 '22 21:10

Mukesh Chapagain