Make refresh Indicator like Skype in iOS
Posted By : Aditya Kumar Sharma | 28-Dec-2016
We are going to make a refresh indicator like Skype
In
So for making this refresh Indicator we have to follow these steps:
func updatingSubviews() {
updateView.frame = CGRect(x: 0, y: 64, width: self.view.frame.width, height: 10)
updateView.backgroundColor = ColorCode().greenColor
self.view.addSubview(updateView)
updateView.hidden = true
}
Now we will add a text to this view to show its updating
let label: UILabel = UILabel()
label.frame.size = updateView.bounds.size
label.text = "Updating..."
label.textAlignment = .Center
label.font = UIFont.systemFontOfSize(8)
label.textColor = UIColor.whiteColor()
updateView.addSubview(label)
add these lines in the updatingSubviews(). Call this fund in viewDidLoad(). The bar is been created, now we have to hide and unhide it accordingly.
Now we will UIRefreshControl to code. Put this on the top where variables are defined
var refreshControl:UIRefreshControl!
Add this function in your code for displaying Refresh controller
//----- Function for displaying Refresh Controller
func refreshControllerUI(){
self.refreshControl = UIRefreshControl()
self.refreshControl.backgroundColor = UIColor.whiteColor()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: #selector(ViewController.refresh(_:)), forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refreshControl)
}
this func is defining the RefreshController and assigning an action refresh(_:) to be performed when refresh control is been refreshing.
Now this the action we need to add:
//------ Method for Refresh
func refresh(sender:AnyObject){
if self.refreshControl.refreshing == true {
self.refreshControl.attributedTitle = NSAttributedString(string: “Please wait”)
}
// Perform task which has to be performed
self.tableView.reloadData()
}
as table is been refreshed so we need to unhide the bar we created. So add this line to refresh(_:)
updateView.hidden = false
Now the final task is to hide the bar when
updateView.hidden = true
Now make the build and run the app.
updateView.hidden = true
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Aditya Kumar Sharma
Aditya is a bright iOS developer, have knowledge of objective C, swift, swift 3, JSON, Core data and iPhone development. Apart from that he loves to travel and explore new things.