views:

411

answers:

4

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?

+1  A: 

Check out Apple's documentation on UIAccessibility.

Ben Gottlieb
Yes, I already read the docs. I was hoping there was a way to do this in IB or in some other elegant way. I posted my kludge solution but am still open for a cleaner approach.
Tim Norman
Sorry, this capability hasn't (yet?) been added to IB. I think you kludge is probably the best you're going to do for now.
Ben Gottlieb
+2  A: 

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.

Tim Norman
A: 

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.

Michael
A: 

I got the code above to work with UIBarButtonItems with one extra line:

[view setIsAccessibilityElement:YES];

Lee Ann Rucker