add accessibility custom slider iOS

2.2k views Asked by At

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.

2

There are 2 answers

0
Justin On BEST ANSWER

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.

1
wilforeal On

If accessible you mean voice over you can do the following pretending mySlider is the name to your Slider Control:

    [mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];

- (IBAction)sliderValueChanged:(UISlider *)sender {
    NSString *valueToAnnounce=[NSString stringWithFormat:@"slider value = %f", sender.value];
    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, valueToAnnounce);
}

This Blog has helped me multiple times with Voice Over questions: http://www.podfeet.com/blog/tutorials-5/build-accessible-ios-apps/