Skip to content

Layout for UICollectionView like Pinterest/waterfall with with options to configure number of columns or larger cells and it allows you to use automatic sizes

License

Notifications You must be signed in to change notification settings

edwinps/CZCustomLayout

Repository files navigation

CZCustomLayout

Version Platform Build Status

CZCustomLayout is a subclass of UICollectionViewFlowLayout.

This layout is inspired by Pinterest, using CHTCollectionViewWaterfallLayout which allows you to use automatic sizes

Features

  • Easy to use.
  • Customizable.
  • Support header and footer views.
  • Custom column number for each sections.

Prerequisite

  • ARC
  • Xcode 7.1+.
  • iOS 9+

How to install

  • CocoaPods

    • Add pod 'CZCustomLayout' to your Podfile.
  • Manual

    • Copy BaseCollectionViewLayout.swift to your project.

How to Use

Step 1

import CZCustomLayout

In order to conform to the BaseCollectionViewLayoutProtocol protocol you have to adopt it in your UIViewController.

Step 2

To conform to the CZeyboardObserverDelegate you have to implement the following functions:

func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForItemAtIndexPath indexPath: IndexPath) -> CGFloat
--option--
func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForHeaderInSection section: Int) -> CGFloat
func collectionView (_ collectionView: UICollectionView, availableWidth: CGFloat, heightForFooterInSection section: Int) -> CGFloat
func collectionView (_ collectionView: UICollectionView, columnCountForSection section: Int) -> Int
func collectionViewBiggerCell(_ indexPath: IndexPath) -> Bool

Step 3

To config the layout in the viewcontroller

//create the Layout
let layout = BaseCollectionViewLayout()
//config margin
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10)
// The minimum spacing to use between rows.
layout.minimumInteritemSpacing = 10
// The minimum spacing to use between columns
layout.minimumLineSpacing = 10
// number of columns or implement collectionView (_ collectionView: UICollectionView, columnCountForSection section: Int) 
layout.numberOfColumns = 2
// Add the layout to your collection view
self.collectionView.collectionViewLayout = layout
//add delegate
layout.delegate = self

Limitation

  • Only vertical scrolling is supported.
  • No decoration view.

License

CZCustomLayout is licensed under the MIT licence. See the LICENSE for more details.

About

Layout for UICollectionView like Pinterest/waterfall with with options to configure number of columns or larger cells and it allows you to use automatic sizes

Resources

License

Stars

Watchers

Forks

Packages

No packages published