[![CI Status](http://img.shields.io/travis/Evan Roth/ERJustifiedFlowLayout.svg?style=flat)](https://travis-ci.org/Evan Roth/ERJustifiedFlowLayout)
This is for an iOS project and can be used on any iPad or iPhone. ERJustifiedFlowLayout
is a subclass of Apple's UICollectionViewFlowLayout
class, which is designed to be used in combination with a UICollectionView
. This project assumes you are familiar with the latter—if not, you can read about UICollectionView
here and you can read about UICollectionViewFlowLayout
here.
ERJustifiedFlowLayout
works with dynamic or static-sized UICollectionViewCells
, as it only handles the layout aspect.
This project contains some code from the following sources: Michael Sand's answer to a question on SO and this Cocoanetics tutorial. Thanks for the inspiration!
To run the example project, clone the repo, and run pod install
from the Example directory first.
Tested on iOS 7 and 8 on all iPads and iPhones from 4S to 6+.
ERJustifiedFlowLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ERJustifiedFlowLayout"
ERJustifiedFlowLayout can be used programmatically in the viewDidLoad
method of the view controller your collection view is in:
ERJustifiedFlowLayout *flowLayout = [[ERJustifiedFlowLayout alloc] init];
or a reference to it can be created from your xib/storyboard like so:
Once instantiated or referenced, ERJustifiedFlowLayout
requires only the setting of one property, with a few others as options:
FlowLayoutHorizontalJustification
—an enum on ERJustifiedFlowLayout
that sets the type of horizontal justification to perform:
FlowLayoutHorizontalJustificationLeft
FlowLayoutHorizontalJustificationFull
FlowLayoutHorizontalJustificationRight
horizontalCellPadding
: controls the amount of absolute space between each cell. Default is 0
. This property overrides the minimumInteritemSpacing
property on UICollectionViewFlowLayout
.sectionInset
: this UICollectionViewFlowLayout
property can be set to provide left, right, top, and bottom section insets which are used in calculating cell justification.
This depicts the following settings:
FlowLayoutHorizontalJustificationLeft, left section inset = 20, horizontalCellPadding = 5
This depicts the following settings:
FlowLayoutHorizontalJustificationFull, left/right section inset = 20, horizontalCellPadding = 5
This depicts the following settings:
FlowLayoutHorizontalJustificationRight, right section inset = 20, horizontalCellPadding = 5
1.0:
Initial version release
1.1:
Fixes issues #2, #4, and #9 (thanks a lot, Sega-Zero!!!)
UICollectionViewScrollDirectionHorizontal
Evan Roth, evanroth@me.com
ERJustifiedFlowLayout is available under the MIT license. See the LICENSE file for more info.