GithubHelp home page GithubHelp logo

yjzalbumcollectionviewlayout's Introduction

YJZAlbumCollectionViewLayout

YJZAlbumCollectionViewLayout is a UICollectionViewLayout subclass, used as the layout object of UICollectionView.

The idea of YJZAlbumCollectionViewLayout is inspired by RFQuiltLayout. The purpose of it is to allow users to create their desired collection layouts simply and straightforward.

Default Custom
Demo 1 Demo 2

How to use

Add the layout as the subclass of your UICollectionViewLayout.

Subclass the layout

The following code is to create the above custom collection layout

- (void) viewDidLoad {
  // ...

  YJZAlbumCollectionViewLayout* layout = (id)[self.collectionView collectionViewLayout];

  [layout clearLayout];
  [layout addLayoutWithRowWidth:320.f rowHeight:100.f layouts:@[[NSValue valueWithCGRect:CGRectMake(0.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(80.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 0.f, 80.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 0.f, 80.f, 100.f)]]];

  [layout addLayoutWithRowWidth:320.f rowHeight:100.f layouts:@[[NSValue valueWithCGRect:CGRectMake(0.f, 0.f, 160.f, 100.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 0.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 0.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(160.f, 50.f, 80.f, 50.f)],[NSValue valueWithCGRect:CGRectMake(240.f, 50.f, 80.f, 50.f)]]];

  layout.delegate = self;

  // ... 
}

- (UIEdgeInsets) insetsForItemAtIndexPath:(NSIndexPath *)indexPath {
  return UIEdgeInsetsMake(2.f, 2.f, 2.f, 2.f);
}

(Note: all delegate methods are optional)

API

All api methods must be called before prepareLayout is called.

// add a custom row layout
- (void) addLayoutWithRowWidth:(CGFloat) rowWidth rowHeight:(CGFloat) rowHeight layouts:(NSArray*) layouts;
//clear all current layouts
- (void) clearLayout;

yjzalbumcollectionviewlayout's People

Contributors

johnny0614 avatar

Watchers

 avatar  avatar

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.