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)

Discussion

Read Community Guidelines
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.