Accessibility label - iOS

On iOS, you can use the accessibilityLabel property to set an accessibility label.

You can also use the attributedAccessibilityLabel property for greater control over pronunciation. For example, spell out each character with .accessibilitySpeechPunctuation or set a language using .accessibilitySpeechLanguage.

The accessibility label should be as short as possible, while still being intuitive. When long labels cannot be avoided, you should use accessibilityUserInputLabels to provide alternative labels. The primary label is first in the array, optionally followed by alternative labels in descending order of importance.

If another element is used to display the label, you can link the label by setting isAccessibilityElement to false and setting accessibilityLabel to the value of the label.

// Set accessibility label
element.accessibilityLabel = "Appt"

// Set accessibility label with Dutch speech engine
element.attributedAccessibilityLabel = NSAttributedString(
  string: "Appt", 
  attributes: [.accessibilitySpeechLanguage: "nl-NL"]
)

// Set accessibility label for controls
element.accessibilityUserInputLabels = ["Appt", "Alternative"]

// Link visual label
label.isAccessibilityElement = false
element.accessibilityLabel = label.text