Coder Social home page Coder Social logo

daametsi / expandablecolumnlayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johntvolk/expandablecolumnlayout

0.0 2.0 0.0 760 KB

Custom column-based UICollectionViewLayout with optional expandable drawer functionality.

License: MIT License

Swift 72.98% Ruby 1.99% Objective-C 1.70% Shell 23.33%

expandablecolumnlayout's Introduction

ExpandableColumnLayout

[![CI Status](http://img.shields.io/travis/John Volk/ExpandableColumnLayout.svg?style=flat)](https://travis-ci.org/John Volk/ExpandableColumnLayout) Version License Platform

A custom UICollectionViewLayout that provides a flexible column-based layout with optional expandable drawer functionality.

  • Arbitrary column count per section
  • Specifiy unit-height or exact height per item
  • Expand or contract sections via attractive drawer-like animation

demo

Installation

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

pod "ExpandableColumnLayout"

Usage

ExpanableColumnLayout relies on an instance of ExpandableColumnLayoutDelegate to provide the information it needs to build the layout. ExpandableColumnLayoutDelegate is a subtype of UICollectionViewDelegate and so inherits any of the required behavior of that protocol. In addition, it adds some required behavior of it's own.

The following two methods must be implemented

func numberOfColumnsInCollectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  forSectionAtIndex section: Int) -> Int;
    
func collectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  sectionIsExpandedAtIndex section: Int) -> Bool;

Additionally, ExpandableColumnLayoutDelegate instances must provide either an exact height or a unit height for each item in a section. There are two ways to accomplish this. Pick whichever makes the most sense for your application.

optional func collectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  itemHasExactHeightAtIndexPath indexPath: NSIndexPath!) -> Bool;
    
optional func collectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  exactHeightForItemAtIndexPath indexPath: NSIndexPath!,
  withWidth width: CGFloat) -> CGFloat;

OR

  optional func collectionView(collectionView: UICollectionView,
    layout expandableColumnLayout: ExpandableColumnLayout,
    unitHeightForItemAtIndexPath indexPath: NSIndexPath!) -> Int;

ExpandableColumnViewController Implementation

The quickest way to get going is to subclass the provided ExpandableColumnViewController. This is the method used in the example project. When you subclass ExpandableColumnViewController there are two methods that you need to override.

public func numberOfItemsInExpandedSection(section: Int) -> Int {
  ...
}

public func viewForSupplementaryHeaderElementAtIndexPath(indexPath: NSIndexPath) -> UICollectionReusableView {
  ...
}

The method viewForSupplementaryHeaderElementAtIndexPath: method only needs to be overriden if you are returning a non-CGZero size from your optional implementation of:

optional func collectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  sizeForHeaderInSection section: Int) -> CGSize;

Custom Implementation

If you don't want to tie yourself to a specific subtype of UIViewController, you'll have to do a bit more work.

First, you'll need to do any bookkeeping of information about expanded sections yourself by providing an implementation of

func collectionView(collectionView: UICollectionView,
  layout expandableColumnLayout: ExpandableColumnLayout,
  sectionIsExpandedAtIndex section: Int) -> Bool;

You can use the provided SectionExpander class to do most of this work for you.

Additionally, you'll need to provide appropriate instances of ExpandableColumnLayoutHeaderKind and ExpandableColumnLayoutSectionBackgroundKind supplementary views in your implementation of

public func collectionView(collectionView: UICollectionView,
  viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView

ExpandableColumnLayout requires an instance of ExpandableColumnLayoutSectionBackgroundKind for every section in the UICollectionView to support the drawer animation.

Author

John Volk, [email protected]

License

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

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.