Search code examples
iosaccessibilityuipagecontrolvoiceover

UIPageControl voiceover issue


I have a UIPageControl in my app's onboarding process. Its purpose is not to change pages manually but as an indication of the user's process through the whole onboarding. (There's no swiping gestures right now)

Everything looks fine, but VoiceOver lets the user increment or decrement the control, and says it can be changed (it seems to keep .adjustable as a trait). I don't want that behaviour. I just want VoiceOver to read "Page 1 of 3". I disabled it, changed its accessibilityTraits and it doesn't affect VoiceOver.

Here is some code.

    /// hard coded values for the example:
    pageControl.numberOfPages = 3
    pageControl.currentPage = 1
    pageControl.isEnabled = false
    pageControl.isUserInteractionEnabled = false
    pageControl.accessibilityTraits = .none

I have created a test project on github for a more complete example.


Solution

  • One way to get your purpose is to subclass UIpageControl and override the accessibiliTraits property as follows:

    class MyPageControl: UIPageControl {
    
        override var accessibilityTraits: UIAccessibilityTraits {
            get{
                return .none
            }
            set{}
        }
    }
    

    Define your pageControl element as MyPageControl to get the desired result.