If you support iOS 9 and later, this behavior is now standard - no special processing is required.
If you support iOS 8 and below, subclass UIPageControl and override accessibilityIncrement and accessibilityDecrement . You do not need to override the accessibilityTraits property to specify it as customizable - UIPageControl configured 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 to ValueChanged and respond accordingly 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 are not a subclass of UIPageControl , this target / action will still be called, but the current page point indicator will not be updated.
Jordan h
source share