Use UIRefreshControl in any UIScrollView(UICollectionView, WebView)

Apple documentation shows us how we can use an UIRefreshControl in an UITableViewController, but do you know, we can add it to any UIScrollView ?

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(handleRefresh), for: .valueChanged)
scrollView.addSubview(refreshControl)

In a similar way, we can add UIRefreshControl to a WKWebView.

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(handleRefresh), for: .valueChanged)
webView.scrollView.addSubview(refreshControl)

Share this

Join

Search articles

Search titles, tags and article content.

    You've successfully subscribed to Developer Insider
    Your account is ready. Welcome to Developer Insider
    Welcome back! You've successfully signed in
    Success! Your account is fully activated, you now have access to all content.