Skip to content

The waterfall (i.e., Pinterest-like) layout for UICollectionView introduced in iOS 6.

License

Notifications You must be signed in to change notification settings

JasonGit/CHTCollectionViewWaterfallLayout

 
 

Repository files navigation

CHTCollectionViewWaterfallLayout

iOS 6 introduced a new feature called UICollectionView. CHTCollectionViewWaterfallLayout is a subclass of UICollectionViewLayout. This layout is inspired by Pinterest. It also is compatible with PSTUICollectionView.

Screen Shots

2 columns 3 columns

Prerequisite

  • ARC
  • Xcode 4.4+, which supports literals syntax.
  • iOS 6+, or
  • iOS 4.x/5.x, with [PSTUICollectionView][1].

How to Use

Read the demo codes for detail information.

Step 1

There are four properties for you to set up.

@property (nonatomic, weak) id<CHICollectionViewDelegateWaterfallLayout> delegate;
@property (nonatomic, assign) NSUInteger columnCount; // How many columns
@property (nonatomic, assign) CGFloat itemWidth; // Width for every column
@property (nonatomic, assign) UIEdgeInsets sectionInset; // The margins used to lay out content in a section

It's your responsibility to set up delegate, columnCount, and itemWidth, they are required. But sectionInset is optional.

Step 2

And you also need to implement one method in your delegate for the CHTCollectionViewDelegateWaterfallLayout protocol.

- (CGFloat)collectionView:(UICollectionView *)collectionView
                   layout:(CHTCollectionViewWaterfallLayout *)collectionViewLayout
 heightForItemAtIndexPath:(NSIndexPath *)indexPath;

Step 3 (Optional)

If you need to support iOS 4.x/5.x and you have installed PSTUICollectionView, then you NEED to modify some codes.

Quoted from PSTUICollectionView README file:

If you want to have PSTCollectionView on iOS4.3/5.x and UICollectionView on iOS6, use PSUICollectionView (basically add PS on any UICollectionView class to get auto-support for older iOS versions)* If you always want to use PSTCollectionView, use PSTCollectionView as class names. (replace the UI with PST)

That's all! Easy, right?

Limitation

  • Only one section is supported.
  • Only vertical scrolling is supported.
  • No supplementary view and decoration view.

License

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

Known Issue

None, so far.

About

The waterfall (i.e., Pinterest-like) layout for UICollectionView introduced in iOS 6.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published