Search code examples
iosswiftaccessibilityuiaccessibility

add accessibility custom slider iOS


I have a custom slider that changes value based on super.beginTrackingWithTouch and super.continueTrackingWithTouch. It follows a quadratic path.

Looking to make the custom slider accessible. Any ideas on how to do it?

I was thinking of adding a standard iOS slider, adding accessibilityLabel, and passing those values to the custom slider. Having trouble making the standard slider functional but invisible to the user though.


Solution

  • It's generally best practice to extend a standard control to perform the special behavior you need. As author of a completely custom control, you're responsible for more of its accessibility.

    Experiment with a UISlider using VoiceOver on your device. See how it behaves. You want to maintain as much of this experience as possible as you implement your own control. You can use Accessibility Inspector in Simulator to explore system controls' accessibility configurations.

    The following steps are almost certainly relevant:

    1. Override or set - (BOOL)isAccessibilityElement to return YES.
    2. Override or set - (CGRect)accessibilityFrame to return an appropriate rectangle in screen coordinates.
    3. Override or set - (UIAccessibilityTraits)accessibilityTraits to include UIAccessibilityTraitAdjustable.
    4. Override - (NSString *)accessibilityValue to describe the current value of your control.
    5. Implement - (void)accessibilityIncrement and - (void)accessibilityDecrement to perform value changes requested by assistive clients such as VoiceOver.

    Beyond the steps above, I can't say what's required for your specific control without more details. If you get stuck, review the Accessibility Programming Guide, UIAccessibility Protocol documentation, and UIAction protocol documentation, and return to StackOverflow with any questions that remain.

    Best luck and thank you for giving this the attention it deserves.