Add activity indicator to the top of UITableView

Nitish Kumar
Jan 11, 2022

In this short article we will see how to add activity indicator on top of UITableView.

For that, you have to create one tableView programmatically or using storyboard.

Step 1: Create one refresh control

// creating UIRefreshControl
lazy
var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()// Add target for UIRefreshControlrefreshControl.addTarget(self, action: #selector(handleRefresh(_:)), for: UIControl.Event.valueChanged)// set tintColor for UIRefreshControlrefreshControl.tintColor = UIColor.greenreturn refreshControl}()@objc func handleRefresh(_ refreshControl: UIRefreshControl) {// do your refreshing partrefreshControl.endRefreshing()}

Step 2: Add UIRefreshControl in tableview

myTableView.addSubview(refreshControl)

Done๐Ÿ˜‡๐Ÿ˜‡๐Ÿ˜‡

Hope you enjoyed reading this post!!

If you have any comment, question, or recommendation, feel free to post them in the comment section below!

Thank you!!! Happy coding.

--

--

Nitish Kumar

I developed and maintain applications aimed at a range of iOS devices including mobile phones and tablet computers.