Giter Site home page Giter Site logo

piterwilson / precalculatedheightcolumnbaseduicollectionviewlayout Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 172 KB

PrecalculatedHeightColumnBasedUICollectionViewLayout is a UICollectionViewLayout subclass where the items are placed in vertical columns that are laid out side by side. Each column has an arbitrary amount of items each with arbitrary heights. Each column is laid out independently from each other. (Looks like UITableView’s synced up to each other)

Objective-C 100.00%

precalculatedheightcolumnbaseduicollectionviewlayout's Introduction

#PrecalculatedHeightColumnBasedUICollectionViewLayout

PrecalculatedHeightColumnBasedUICollectionViewLayout

PrecalculatedHeightColumnBasedUICollectionViewLayout is a UICollectionViewLayout subclass where the items are placed in vertical columns that are layed out side by side. Each column has items of arbitrary heights.

The height of the items is provided by the items themselves (implementing the PrecalculatedHeightObject protocol). The protocol contains a sinle property that must be implemented:

-(float)precalculatedHeight;

The width of the columns is specified by the layout. (columnWidth property) as is the internal spacing between columns (columSpacing, rowSpacing properties)

Example :

The pseudo data structure

[
  [
      {precalculatedHeght : 1}
  ],
  [
      {precalculatedHeght : 1},
      {precalculatedHeght : 2},
      {precalculatedHeght : 3}
  ],
  [
      {precalculatedHeght : 1},
      {precalculatedHeght : 2},
      {precalculatedHeght : 2}
  ]
]

Results in:

┌─────┬─────┬─────┐
|  1  |  1  |  1  |
└─────┼─────┼─────┤
     |  2  |  2  |
     |     |     |
     ├─────┼─────┤
     |  3  |  2  |
     |     |     |
     |     ├─────┘
     └─────┘

#Installation

Download the sample project and copy the files under the PrecalculatedHeightColumnBasedUICollectionViewLayout folder

#Usage

##PrecalculatedHeightColumnBasedUICollectionViewLayoutDataSource

PrecalculatedHeightColumnBasedUICollectionViewLayout needs an object to act as its dataSource. The class may be of any type as long as it implements the PrecalculatedHeightColumnBasedUICollectionViewLayoutDataSource protocol.

-(id <PrecalculatedHeightObject>)objectForColumn:(int)column position:(int)position;

This call should return the Object that is positioned at the specified column and position (row) inside that column. The Object should implement the PrecalculatedHeightObject protocol.

-(int)numberObjectsInColumn:(int)column;

This call should return the number of Objects in the given column index.

-(int)numberColumns;

This call should return the number of columns to use on the layout.

##PrecalculatedHeightObject

A simple protocol with a single property to override

-(float)precalculatedHeight;

The property should return the height in pixels for this object in the layout.

Sample

See attached Xcode project (Sample was made with XCode 6.2)

License

MIT

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.