Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRefreshControl appears on top of collection view items instead of behind

I have a UICollectionView with the regular pull to refresh implementation, but somehow the spinner and the "pull to refresh" text appear above the collection view items;

How can I make it behind the items?

This is how I add the UIRefreshControll to the UICollectionView

let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull down to refresh")
refreshControl.addTarget(self, action: #selector(pullToRefresh), for: UIControlEvents.valueChanged)
collectionView?.refreshControl = refreshControl
like image 825
Ivan Cantarino Avatar asked Jul 24 '17 10:07

Ivan Cantarino


People also ask

How do you add a pull to refresh in collection view in Swift?

You can add a refresh control to a table or collection view by assigning an instance of the UIRefreshControl class to this property. If your application targets versions prior to iOS 10, you simply add the refresh control as a subview to the table view.

What is refresh control swift?

Overview. A UIRefreshControl object is a standard control that you attach to any UIScrollView object, including table views and collection views. Add this control to scrollable views to give your users a standard way to refresh their contents.


1 Answers

The way I figure this out is to change the refreshControll zPosition to be behind every view with the following:

refreshControl.layer.zPosition = -1

Hope this helps anyone further.

like image 77
Ivan Cantarino Avatar answered Nov 15 '22 20:11

Ivan Cantarino