10

When using voice over on the springboard, when the UIPageControl at the bottom of the screen is selected, VoiceOver announces something like "Page 1 of 5. Adjustable." and the user can swipe up and down to change pages.

In my app, I do not get the "Adjustable" part, and the pages cannot be changed by swiping.

Any ideas how I fix this? It obviously kills the usability of the app.

1
  • Are you doing this in InterfaceBuilder or programatically? It sounds like it's missing the trait UIAccessibilityTraitAdjustible — are you using the Page Control directly or inside another view that knows how to manage it?) Commented Apr 20, 2012 at 5:37

3 Answers 3

8

I have subclassed UIPageControl and overrode the -accessibilityTraits getter to return UIAccessibilityTraitAdjustable getting Voice Over to read "adjustable".

To add actions: implement the -accessibilityIncrement and -accessibilityDecrement methods specified in the UIAccessibilityAction category.

Since my pages respond to the UIControlEventValueChanged events, I make sure to send actions for this event too.

Sample code

@interface AccessibleUIPageControl : UIPageControl

@end

@implementation AccessibleUIPageControl

- (UIAccessibilityTraits)accessibilityTraits
{
    return super.accessibilityTraits | UIAccessibilityTraitAdjustable;
}

- (void)accessibilityIncrement
{
    self.currentPage = self.currentPage + 1;
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}

- (void)accessibilityDecrement
{
    self.currentPage = self.currentPage - 1;
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}

@end
1
  • 1
    Usually, you combine the traits from super with the desired traits, like return super.accessibilityTraits | UIAccessibilityTraitAdjustable.
    – Adrian
    Commented May 18, 2015 at 18:54
5

If you're supporting iOS 9 and newer, this behavior is now the standard - no special handling required.

If you're supporting iOS 8 and lower, subclass UIPageControl and override accessibilityIncrement and accessibilityDecrement. You don't need to override the accessibilityTraits property to indicate it's adjustable - UIPageControl is adjustable by default.

import UIKit

class AccessibleUIPageControl: UIPageControl {

    override func accessibilityIncrement() {
        self.currentPage += 1
        self.sendActionsForControlEvents(.ValueChanged)
    }

    override func accessibilityDecrement() {
        self.currentPage -= 1
        self.sendActionsForControlEvents(.ValueChanged)
    }

}

Then in your view controller you can listen for ValueChanged and respond appropriately to show the content for the new page:

//viewDidLoad:
self.pageControl.addTarget(self, action: "didChangePage", forControlEvents: .ValueChanged)

func didChangePage() {
    let contentOffset: CGFloat = collectionView.frame.size.width * CGFloat(pageControl.currentPage)
    collectionView.setContentOffset(CGPointMake(contentOffset, 0), animated: false)
}

Note that if you don't subclass UIPageControl this target/action will still be called but the current page dot indicator will not update.

2
  • Hi, the issue I'm having with page control is that I'm unable to get it to increment or decrement the counter when the focus is on it. I'm targeting platforms iOS 10 and above. Any way to help me out? Thanks! Commented Feb 26, 2018 at 20:48
  • @KarthikKannan Sorry I haven't seen that issue myself
    – Jordan H
    Commented Feb 26, 2018 at 21:09
-1

I still needed to implement the Custom AccessiblePageControl using iOS 10+ (as suggested above). I followed the approach above but linked an IBAction on my storyboard for both touchUpInside and valueChanged.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.