Skip to content

BrokoliMobile/CollectionViewPageFlowLayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CollectionViewPageFlowLayout

CollectionViewPageFlowLayout is a paged collection view flow layout in Swift

Usage

In any UICollectionViewController (or any UIViewController with a UICollectionView) create a CollectionViewPageFlowLayout instance and assign it to the collectionViewLayout property of the UICollectionView.

let pagedLayout = CollectionViewPageFlowLayout()
self.collectionView.collectionViewLayout = pagedLayout

That's it. Now you don't have to worry about the size changes of your collection view or the interface orientation of your view controller. The layout will always make sure it's paged.

A paged collection view

Page separators

Out of the box, the layout will make it look like your collection view's pages are stuck together. There are no margins between them. You can change this by setting the minimumLineSpacing property to a non-zero value. This will add spaces before and after the collection view items. Of course, you don't have to worry about the item size. The layout will take care of that for you. Just make sure you resize your collection view beyond it's superview so that the spaces are only visible while scrolling.

self.collectionView.frame = CGRectInset(self.view.bounds, -2, 0)
let pageLayout = self.collectionView.collectionViewLayout as CollectionViewPageFlowLayout
pageLayout.minimumLineSpacing = 4

A paged collection view with separator margins

About

A paged collection view flow layout in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages