Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2017 14:02
  • Star 23 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
@objc protocol Refreshable
/// The refresh control
var refreshControl: UIRefreshControl? { get set }
/// The table view
var tableView: UITableView! { get set }
/// the function to call when the user pulls down to refresh
@objc func handleRefresh(_ sender: Any);
extension Refreshable where Self: UIViewController
/// Install the refresh control on the table view
func installRefreshControl()
let refreshControl = UIRefreshControl()
refreshControl.tintColor = .primaryColor
refreshControl.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged)
self.refreshControl = refreshControl
if #available(iOS 10.0, *)
tableView.refreshControl = refreshControl
tableView.backgroundView = refreshControl
Copy link

@aalenliang, u just need to change the tableView property to a scrollView property on your protocol and add scrollView.refreshControl = refreshControl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment