Making NSSegmentedControl segments accessible

Viewed 77

My AppKit app's NSSegmentedControl doesn't show any labels in the Accessibility Inspector, meaning that disabled users won't be able to use assistive devices to interact with them. Calling setAccessibilityLabel and setAccessibilitySelected on the segment controls has no effect.

Similar advice on the topic (e.g., Disable / hide accessibility element) says to use accessibilitySetOverrideValue, which does work, but it is deprecated:

accessibilitySetOverrideValue(_:forAttribute:)' was deprecated in macOS 10.10: Use the NSAccessibility protocol methods instead (see NSAccessibilityProtocols.h)

The Apple docs at https://developer.apple.com/documentation/objectivec/nsobject/1535843-accessibilitysetoverridevalue read:

This method is deprecated. Use the new method-based API instead. For more information, see Accessibility Programming Guide for OS X or NSAccessibilityProtocol.

However, there doesn't seem to be any equivalent method to override an accessibility value. How can I accomplish this without using deprecated methods?

1 Answers

NSSegmentedControl will pick up the accessibilityDescription of the image. So the solution I used was to ensure all my segmented controls have images, and for each one, if necessary, make a copy of the image, set the accessibilityDescription explicitly, and reset the image.

Ugly, but better than any other solution I found.

Related