Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS accessibility - How do you set the accessibility label for the title of a UINavigationBar?

Apple's voice over mispronounces the title of one of my views, which is inside a UINavigation Controller.

In other parts of the app I have added a custom accessibility label to help it pronounce the company name correctly. How can I set the accessibility label of a UINavigationBar?

like image 480
Robert Wagstaff Avatar asked Jul 24 '12 01:07

Robert Wagstaff


People also ask

What is accessibility label?

For a text input field, its accessible label would be a short description of the data the field collects. For a control that is a group of options, such as a drop-down menu or list of radio buttons or checkboxes, the group should have a label that describes the relationship of the options.

How do I make my IOS app accessible?

Start by enabling VoiceOver in the Settings app, under General > Accessibility. If you haven't used VoiceOver before, you can scroll around using three-finger swipes, select elements by tapping on them, and activate controls by double tapping. Make sure all elements have accessibility labels.


2 Answers

This works in iOS 8.2. In viewDidLoad:

self.navigationItem.accessibilityLabel = @"My accessible label";

When a navigation controller transitions to the view controller, the accessibilityLabel is read instead of the view controller title.

like image 173
stevekohls Avatar answered Sep 19 '22 16:09

stevekohls


I couldn't add an accessibility label, but I found a workaround:

I replace the navigationItem's title View with a UILabel that has accessibility set up.

UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"myTitle";
[titleLabel setAccessibilityLabel:@"myCustomAccessiblityLabel"];
[titleLabel setFont:[UIFont boldSystemFontOfSize:20.0]];
[titleLabel setBackgroundColor:[UIColor clearColor]];
[titleLabel setTextColor:[UIColor whiteColor]];
[titleLabel sizeToFit];
self.navigationItem.titleView = titleLabel;

I'm not sure why setting the accessibility label doesn't work, but the above code works for my needs.

like image 27
Robert Wagstaff Avatar answered Sep 20 '22 16:09

Robert Wagstaff