iosswiftuirefreshcontroluiaccessibilityxcode9.2

How to add accessibility for UIRefreshControl in Swift


I am trying to add accessibility for UIRefreshControl which has been implemented for pull to refresh in UITableView as below

self.refreshControl.accessibilityLabel = "Refreshing"

But if accessibility turned on and by swiping three finger on UITableview then does not speaking as Refreshing.

I override accessibilityScroll method as below.

override func accessibilityScroll(_ direction: UIAccessibilityScrollDirection) -> Bool {
    if direction == .up {
        self.refreshControl.accessibilityLabel = "Refreshing"
    }
    return true
}

Any idea Thanks!


Solution

  • Firstly, refreshing is more than just scrolling up. Its scrolling up past y position 0. Otherwise this will happen whenever the user scrolls up. Secondly, use UIAccessibilityPostNotification to announce to the user that a UI element has just changed.