LMCenteredCollectionView
is a infinite scroll view.
Create your cell,
class YourCell: LMCenteredCollectionViewCell {}
Then show centeredCollectionView in YourViewController
,
class YourViewController: UIViewController {
private var centeredCollectionView: LMCenteredCollectionView!
override func viewDidLoad() {
centeredCollectionView = LMCenteredCollectionView(frame: UIScreen.main.bounds, direction: .horizontal)
centeredCollectionView.register(YourCell.self)
view.addSubview(centeredCollectionView)
}
}
You must implement dataSource
to show your contents,
centeredCollectionView.dataSource = self
extension YourViewController: LMCenteredCollectionViewDataSource {
func numberOfItems(in centeredCollectionView: LMCenteredCollectionView) -> Int {
return 10
}
func centeredCollectionView(_ centeredCollectionView: LMCenteredCollectionView, cellForItemAt index: Int) -> LMCenteredCollectionViewCell {
let cell = centeredCollectionView.dequeueReusableCell(for: index) as! YourCell
return cell
}
}
Implementing delegate
if you want to resize items and spacing between items. The default size is (50, 50) and the interitemSpacing is 10.
For more control you can see LMCenteredCollectionViewDelegate
for detail.
centeredCollectionView.delegate = self
extension YourViewController: LMCenteredCollectionViewDelegate {
func sizeOfItems(in centeredCollectionView: LMCenteredCollectionView) -> CGSize {
return CGSize(width: 50, height: 50)
}
func interitemSpacingBetweenItems(in centeredCollectionView: LMCenteredCollectionView) -> CGFloat {
return 10
}
}
Add LMCenteredCollectionView
in your Podfile
.
pod 'LMCenteredCollectionView'
Then,
pod install
Copy Sources
folder to your project. That's it.
The MIT License (MIT)