Custom Accessibility Actions for iOS

Mikhail Sinanan
Technology at NPR
Published in
3 min readApr 14, 2017

--

UIAccessibilityCustomAction is a class that you will rarely see when researching accessibility for your application, but will make your app more accessible without putting in a ton of dev work.

How can custom actions improve accessibility in my app?

The standard iOS accessibility tools do most of the heavy lifting to make your app accessible. Many of the components in UIKit expose some information to the accessibility framework, so there is not much work to do to support them. However, if your application has actions or features that are activated with hidden/power-user interactions, such as 3D touch, multiple taps, swipe-to-reveal, etc., custom actions can make those interactions easier for people who use assistive technologies.

How am I using custom actions?

I am currently working on a redesign of the NPR News app and one of the goals is to make the app as inclusive as possible. So, we designed components in the app with accessibility in mind. For instance, the cells on the home screen have hidden actions underneath that are revealed when a user swipes on it. Accessing these actions with accessibility tools turned on is pretty difficult, so it is a great place to attach custom actions.

Here is a quick demo showing the swipe functionality on the cells.

Now here is a demo showing how to share a story without swiping. This will be using the Accessibility Inspector to show the accessibility info and trigger the custom share action.

How to implement custom actions?

Implementing a UIAccessibilityCustomAction is pretty simple. I will walk through how I implemented the custom share action demoed above.

  1. Subclass UIAccessibilityCustomAction.
    I made my own subclass to include a NSIndexPath property, which I can send to my datasource to retrieve the correct story. I chose NSIndexPath because I’m attaching these actions to cells inside a UITableView. Feel free to add the appropriate object to this subclass that will help identify which action was activated, if there are multiple items with these actions.
//
// NPRAccessibilityAction.h
#import <UIKit/UIKit.h>@interface NPRAccessibilityAction : UIAccessibilityCustomAction@property (nonatomic) NSIndexPath *indexPath@end

2. Set the cell’s custom accessibility actions.
Tip: make the custom action name something short and descriptive of the action. I used “share.” This name will be exposed to the user.

# pragma mark - UITableViewDelegate Methods- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {//Create custom Share Accessibility action for all cells
NPRAccessibilityAction *shareAction = [[NPRAccessibilityAction alloc] initWithName:@"share" target:self selector:@selector(myPerformActionMethod:)];
shareAction.indexPath = indexPath;cell.accessibilityCustomActions = @[shareAction];
}

3. Implement the method which will get called from the custom action

- (BOOL)myPerformActionMethod:(NPRAccessibilityAction *)action {   if ([action.name isEqualToString:@"share"] && action.indexPath) {
return [self shareStoryForIndexPath:action.indexPath];
}
return NO;
}

4. Test it! Use the accessibility inspector to reveal accessibility information about elements in your app.

How to open the Accessibility Inspector

If you successfully added the custom actions, it will show up under the actions section.

That’s it for adding custom actions to your app’s components. I hope this post was useful and will help make your app more accessible.

Resources

Nice overview on how to use accessibility on device -http://axslab.com/articles/ios-voiceover-gestures-and-keyboard-commands.php

Official Apple documentation - https://developer.apple.com/reference/uikit/uiaccessibilitycustomaction

--

--

Sr. Manager, Mobile Payments Lead for @CapitalOne. Formerly of @NPR, @AtlanticMedia & @SAS. Enthusiast of photography, music, fashion, food, and the seminoles.