개발/swift

Implement collectionview pull to refresh

lemonade 2021. 1. 27. 10:00
반응형

How to add pull to refresh on collectionview?

 

 

Pull to refresh is often used in lists.

 

It's not hard to add pull to refresh on collectionview.

 

You can use UIRefreshControl to implement it.

 

 

 

Set collectionview refreshControl.

 

You can custom refreshControl color by tintColor property, size by scale and you can even set title.

 

 

 

And implement selector function.

 

You should call your data refresh function inside it.

 

And after load data, call endRefreshing() to hide refreshControl.

 

 

Noted)

 

When collectionview is empty, refresh function might not called.

 

Because collectionview is not scrolled. 

 

In that case, just set alwaysBounceVertical or alwaysBounceHorizontal property to true.

 

Happy codding :)

 

반응형
그리드형