This repository aims to provide a simple way of implementing an infinite collection view.
By infinite, we mean that as soon as a user reaches the boundary of the collection view
content, the content will then loop back to the start in a circular manner.
In order to use InfiniteCollectionView:
- Make it the custom subclass of a UICollectionView component in your storyboard.
- Set the infiniteDataSource (not the standard UICollectionView dataSource) and implement the required functions.
The custom datasource is very similar to the standard UICollectionViewDataSource. There are 3 functions to implement:
func cellForItemAtIndexPath(collectionView: UICollectionView, dequeueIndexPath: NSIndexPath, usableIndexPath: NSIndexPath) -> UICollectionViewCell
This function operates exactly the same as the regular cellForItemAtIndexPath, however, you should use dequeueIndexPath
for dequeuing your cell and usableIndexPath
for your content.
func numberOfItems(collectionView: UICollectionView) -> Int
As with the standard UICollectionViewDatasource, simply return the number of cells of content you have.
You can use InfiniteCollectionView to scroll infinitely in a horizontal direction with equally sized cells.
Improvements will include vertical scroll support and support for various cell sizes.