ugomarinelli / PullToRefresh

Swift 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pull To Refresh πŸ‘†


1 - On a Table view πŸ“‰

ljJEmq

πŸ” Create a Table view in your interface and drag it to create an outlet

πŸ” Create a refresh control object as a global variable :

var refreshControl: UIRefreshControl!

πŸ” In the viewDidLoad, initialize your refresh control and add it to your table view

// Initialize the refresh control.
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
tView.addSubview(refreshControl)

πŸ” Implement the refresh method that will be called when the user refreshes your table view

//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}

2 - On a UIView πŸ“Ί

NZj8f4

πŸ” Create a ScrollView in the interface builder and create an outlet

πŸ” In the interface builder, select the scroll view and make sure to check "Bounce Vertically" :

aM8hfB

πŸ” Drag a view inside the Scroll View hierarchy within the interface builder and create an outlet

πŸ” Create a refresh control object as a global variable :

var refreshControl: UIRefreshControl!

aM8hfB C. Drag a view inside the Scroll View hierarchy within the interface builder and create an outlet

πŸ” In the viewDidLoad, instantiate your refresh control and add it to your scrollView

// Initialize the refresh control.
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)

//Adding refreshing to scroll view
self.scrollView.addSubview(refreshControl)

πŸ” Implement the refresh method that will be called when the user refreshes your table view:

//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}

About

Swift 3

License:MIT License


Languages

Language:Swift 100.0%