Accessibility iOS Development

Accessibility improvements for UISearchController

By implementing UISearchController you can easily add search functionality to any UITableView. However, having such a search bar might have accessibility drawbacks. It might even be completely unusable users relying on Voice Over.

This article is part of my more technical accessibility related content. You can see all of my accessibility articles by using the following link:

Quick Summary

Make sure you are not relying on scrolling gestures for showing / hiding UI elements in general. When doing so, Voice Over user might never be able to focus these elemnts. Set hidesSearchBarWhenScrolling accordingly on the navigationItem associated with your search bar, e.g. check for UIAccessibility.isVoiceOverRunning, add a button for showing hiding or always show it to everybody.

Hiding showing UI elements on demand

It might seem reasonable to hide or show UI elements on demand, e.g. to save space on your screen or make it look less cluttered. However, this often can have usability or accessibility drawbacks, in fact the default UISearchController is a good (or bad) example for that as we see in the following section.

Another example is when having a button, it’s most of the times clearer to the user on how to proceed by just disabling it, instead of hiding it completely.

So, let’s say for interactive elements it’s often a bad idea to conditionally hide or show them. At least double check if it really makes sense

Hiding or showing the search bar

There is a built-in feature for the search bar on iOS making it possible to hide it whenever it is not needed. That means, when you scroll inside of the table view, it will also disappear. As you are most likely not want to interact with the search bar while scrolling, this makes sense. You can see this behavior also inside of Apple’s Mail App.

However, when you are using Voice Over, you cannot actually “scroll” to show or hide it. And it also would not be really useful because you are navigating by swiping and focusing elements. Focusing is the important thing here. If the search bar is hidden you also cannot focus it, making it unusable for Voice Over users.

Fixing UISearchController for Accessibility

If we have another look at Apple’s Mail App, you will see that the search bar is always there as soon as you are enabling Voice Over. How can we achieve that? It’s actually pretty easy and just requires two things:

  1. You can change the behavior of the showing / hiding by setting hidesSearchBarWhenScrolling on your navigationItem (most probably the UIViewController where you are showing your search bar). See the Apple’s docs for more information:
  2. As it still might be useful to hide and show the search bar for non Voice Over users, you can make the aforementioned setting depending on whether Voice Over is running. You can simply do that by checking for UIAccessibility.isVoiceOverRunning. Also see Apple’s docs for more information:

As a small warning or side not, please do not overdo it with checks for certain accessibility features. Often when there is the need for these checks, there might be an underlying usability issue.

With that in mind: Solve for one, extend to many

Leave a Reply

Your email address will not be published. Required fields are marked *