Is there a way to customise Accessibility label on the navigation bar back button?

Cherie CH. picture Cherie CH. · Oct 12, 2015 · Viewed 7.5k times · Source

I am trying to find a way to customise the accessibility label for the back button on the navigation bar for voiceover feature. I know the accessibilityLabel feature is used to customise the elements, however I can't seem to be able to do it for the navigation bar's back button. Any advice on how I should approach this issue?

I am developing on iOS 8, using Swift.

Answer

Teja Nandamuri picture Teja Nandamuri · Oct 13, 2015

No, you cannot use any other than accessibilityLabel to set the accessibilityLabel for an element. Your other otpion is setting the accessibilityHint. But you should always set the accessibilityLabel.

You can set the accessibility for the back button as:

You can customise your accessibilityLabel string but not accessibilityLabel.

Obj-C:

[self.navigationController.navigationBar.backItem setAccessibilityLabel:@"your string"];

Swift:

self.navigationController.navigationBar.backItem.setAccessibilityLabel("your string")

Swift 2.2

self.navigationController?.navigationBar.backItem?.accessibilityLabel = "your string"

You can also change the traits for an element.for that look into UIAccessibilityTraits