Accessibility and default values in UIKit
You’ve probably noticed this but in case you haven’t, UIControl
elements added to a UIStoryboard
are accessible by default.
Isn’t this a good thing?
Yes. This is usually a great thing. It was the right call by Apple. Can you imagine having to go through your storyboard files manually toggling every UIControl
to enabled and having to consider the label, hint and identifier values? It would be a nightmare. Apple saves you the pain of this but it can lead to unexpected consequences.
What consequences?
It is very rare but there are occasions where it is a valid practice to include an element that the user should not see.
Since accessibility for elements is the default behavior, you’ve just added an element to the page that will show up on a screen reader.
One other thing to consider.
Another default behavior for controls is that they are enabled.
In the example above, not only can a vision impaired user “see” the element through the screen reader. They will have no way of knowing that you’ve added that element as a workaround. Furthermore because elements like UIButton
default to enabled, they can select it! This could lead to unexpected behaviors ranging from corrupted data to a crash.
How fix?
Really simple, just make sure you do not have Accessibility or User Interaction Enabled toggled.
In two checkboxes you’ve made your app safer and improved the screen reader experience. Hooray!
Thanks for reading!