Skip to content

Library used to provide different type of custom Layouts within 30 second of time

License

Notifications You must be signed in to change notification settings

mwaqasbhati/WBCollectionViewLayout

Repository files navigation

WBCollectionViewLayout

It provides 4 different type of Custom layout for CollectionView.

Two Cell Layout Three Cell Left Layout Three Cell Right Layout Mix Layout
Demo Demo Demo Demo
Demo Demo Demo Demo

Contents

Requirements

  • iOS 9.0+
  • Swift 4.0

Installation

Manually

Download the Code and Copy the layout file -> WBCollectionViewLayout.swift into your project. That's it.

CocoaPods

WBCollectionViewLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'WBCollectionViewLayout', :git => 'https://github.com/mwaqasbhati/WBCollectionViewLayout.git'

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

  • Just Create a WBGridViewLayout object and Confirm to it's Delegate
let mlayout = WBGridViewLayout()
mlayout.delegate = self
collectionView.setCollectionViewLayout(layout, animated: true)

Note: Delegates methods are optional and in default case Mixture layout will be drawn but if you want more customization then you need to implement it's delegates

Two Cell Layout

func colectionView(_ collectionView: UICollectionView, numberOfItemsInRow row: Int) -> CellLayout {
   return .Two
}

Three Cell Left Layout

func colectionView(_ collectionView: UICollectionView, numberOfItemsInRow row: Int) -> CellLayout {
   return .ThreeLeft
}

Three Cell Right Layout

func colectionView(_ collectionView: UICollectionView, numberOfItemsInRow row: Int) -> CellLayout {
   return .ThreeRight
}

Mixutre Cell Layout

This Layout is the default one and you don't have to implement numberOfItemsInRow delegate.

Custom Cell Layout

  • If you want more customization in drawing the layout then you can optionally implement it's delegate methods given below which provides numberOfItemsInRow for each Row and size of each Row.
func colectionView(_ collectionView: UICollectionView, numberOfItemsInRow row: Int) -> CellLayout
func colectionView(_ collectionView: UICollectionView, sizeOfItemInRow row: Int) -> CGSize?

Tips

When you load data from service

In case you load data asynchronously please follow next steps:

when data is loaded invalidate layout as well as reload data on collection view.

collectionView.collectionViewLayout.invalidateLayout()
collectionView.reloadData()

Author

mwaqasbhati, [email protected]

License

WBCollectionViewLayout is available under the MIT license. See the LICENSE file for more info.

About

Library used to provide different type of custom Layouts within 30 second of time

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published