I am working on making my iPhone app accessible. I have several UIBarButtonItem objects in Interface Builder, and I cannot find any option to set the accessibility label or hint for these buttons.
How can I set these attributes?
I am working on making my iPhone app accessible. I have several UIBarButtonItem objects in Interface Builder, and I cannot find any option to set the accessibility label or hint for these buttons.
How can I set these attributes?
Okay, so it seems there's no way to do it in Interface Builder, even though you can set accessibility attributes on other UI elements using IB. So I set a tag on my toolbar and then added this code to my viewWillAppear method:
UIToolbar *bottombar = (UIToolbar*)[self viewWithTag:kBottomToolbar];
UIView *view = (UIView*)[bottombar.items objectAtIndex:0];
[view setAccessibilityLabel:NSLocalizedString(@"Add Bookmark", @"")];
[view setAccessibilityHint:NSLocalizedString(@"Add Bookmark", @"")];
and so on for each button item...
Not the most elegant, but it works.
Trying to set accessibility labels manually didn't work for me with UIBarButtonItem images. However, if I set the title manually then the label would work. But it displays the title below the image.
I ended up creating an UIButton and using it as a custom view for the UIBarButtonItem. The only loss being the image masking that UIBarButtonItem performs. Added bonus: accessibility configurable in IB.
I got the code above to work with UIBarButtonItems with one extra line:
[view setIsAccessibilityElement:YES];