I'm using:
My CollectionView code is pretty simple:
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
   super.viewDidLoad()
   let refreshControl = UIRefreshControl()
   refreshControl.addTarget(self, action: #selector(onRefresh), for: .valueChanged)
   refreshControl.isUserInteractionEnabled = false
   collectionView.alwaysBounceVertical = true
   collectionView.refreshControl = refreshControl
}
@objc private func onRefresh(refreshControl: UIRefreshControl) {
   refreshControl.endRefreshing()
}
After I pull collectionView and the refreshControl will appear, if I scroll collectionView back to the top, then the refreshControl is drawn over the cells:

I found the solution for this case:
refreshControl.layer.zPosition = -1
But now Refresh Controll lies behind cells and viewed through spaces between them:

The result I want to get is very simple and logical. I assume that it works with the TableView since the cells in it have background filling. Why did not Apple initially support this approach with a CollectionView:

you just need to add the following after the instance of refreshcontrol is set:
        refreshControl.backgroundColor = UIColor.white
        refreshControl.tintColor = UIColor.black
Hope this helps~
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With