Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To direct the accessibility focus towards a UIBarButtonItem, you can use the accessibilityElement property of the navigation bar that contains the item.

Here's an example:

// create a UIBarButtonItem
let buttonItem = UIBarButtonItem(title: "Button", style: .plain, target: nil, action: nil)

// add it to the navigation bar
navigationItem.rightBarButtonItem = buttonItem

// set the accessibility label and hint for the UIBarButtonItem
buttonItem.accessibilityLabel = "Button item"
buttonItem.accessibilityHint = "Activate button"

// set the navigation bar's accessibilityElements property to include the button item
navigationController?.navigationBar.accessibilityElements = [buttonItem]

In this example, we create a UIBarButtonItem and add it to the navigation bar. Then, we set its accessibility label and hint. Finally, we set the navigation bar's accessibilityElements property to include the button item, so that it will receive focus when the user navigates through the interface using assistive technology.