Pinterest inspired layout for UICollectionViews
Note: Updated for Swift 2.0 and cocoapods
CollectionViewWaterfallLayout is a subclass of UICollectionViewLayout written completely in Swift. This class is based off CHTCollectionViewWaterfallLayout which was written by chiahsien in Objective C. This class tries to use as many new Swifty things to keep the code updated with current design patterns.
The original layout was inspired by Pinterest.
- Easy to use - If you are used to working with UICollectionViewFlowLayout, this should feel natural
- Highly Customizable
- Outstanding Performance
- Supports headers and footers
- ARC
- iOS 7+
- Xcode 7+
- Swift 2.0
CollectionViewWaterfallLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "CollectionViewWaterfallLayout"
Check out the demo project for an example using storyboards to set up the views, and that programmatically creates and customizes the waterfall layout.
Below are the public properties and their default values that you can change to customize the layout
var columnCount:Int = 2
var minimumColumnSpacing:Float = 10.0
var minimumInteritemSpacing:Float = 10.0
var headerHeight:Float = 0.0
var footerHeight:Float = 0.0
var headerInset:UIEdgeInsets = UIEdgeInsetsZero
var footerInset:UIEdgeInsets = UIEdgeInsetsZero
var sectionInset:UIEdgeInsets = UIEdgeInsetsZero
Your collection view's delegate must conforms to CollectionViewWaterfallLayoutDelegate
protocol and implement the required method, all you need to do is return the original size of the item:
func collectionView(collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
- Only vertical scrolling is supported.
- No decoration view.
CollectionViewWaterfallLayout is available under the MIT license. See the LICENSE file for more info.