Coder Social home page Coder Social logo

lisafiedler / chtcollectionviewwaterfalllayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chiahsien/chtcollectionviewwaterfalllayout

0.0 0.0 0.0 2.34 MB

The waterfall (i.e., Pinterest-like) layout for UICollectionView.

License: MIT License

chtcollectionviewwaterfalllayout's Introduction

CHTCollectionViewWaterfallLayout

Version Platform

CHTCollectionViewWaterfallLayout is a subclass of UICollectionViewLayout, and it trys to imitate UICollectionViewFlowLayout's usage as much as possible.

This layout is inspired by Pinterest. It also is compatible with PSTCollectionView.

Screen Shots

2 columns 3 columns

Prerequisite

  • ARC
  • Xcode 4.4+, which supports literals syntax.
  • iOS 6+, or
  • iOS 4.x/5.x, with PSTCollectionView.

How to Use

Read the demo codes and CHTCollectionViewWaterfallLayout.h header file for more information.

Step 1

There are some properties for you. Although they have default values, I strongly recommand you to set up columnCount to suit your needs.

@property (nonatomic, assign) NSInteger columnCount;
@property (nonatomic, assign) CGFloat minimumColumnSpacing;
@property (nonatomic, assign) CGFloat minimumInteritemSpacing;
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, assign) CGFloat footerHeight;
@property (nonatomic, assign) UIEdgeInsets sectionInset;

Step 2

Your collectionView's delegate (which often is your view controller) must conforms to CHTCollectionViewDelegateWaterfallLayout protocol and implements the required method:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

Step 3 (Optional)

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

Quoted from PSTCollectionView 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)

Limitation

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

License

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

Changelog

0.0.6

  • [Add] Add minimumColumnSpacing and minimumInteritemSpacing properties.
  • [Remove] Remove itemWidth property. The layout object will calculate a proper item width automatically.
  • [Change] Rename delegate method - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout heightForItemAtIndexPath:(NSIndexPath *)indexPath to - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath. It should return original size for each item.
  • [Fix] Section header and/or footer should work properly.
  • [Fix] Use sectionInset correctly.

0.0.5

  • [Add] Multiple sections.
  • [Add] Header and/or footer for section.
  • [Add] More properties and delegation methods.
  • [Change] Remove delegate property, your collectionView's delegate MUST conforms to <CHTCollectionViewDelegateWaterfallLayout> protocol.

chtcollectionviewwaterfalllayout's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.