Latest 1.0.0
Homepage https://github.com/johnny0614/YJZAlbumCollectionViewLayout
License MIT
Platforms ios 6.0, requires ARC
Authors

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;

Latest podspec

{
    "name": "YJZAlbumCollectionViewLayout",
    "version": "1.0.0",
    "license": "MIT",
    "summary": "YJZAlbumCollectionViewLayout is a subclass of UICollectionViewLayout that positions various sized cells like a maison laying bricks.",
    "homepage": "https://github.com/johnny0614/YJZAlbumCollectionViewLayout",
    "authors": {
        "YU JOHNNY ZHOU": "[email protected]"
    },
    "source": {
        "git": "https://github.com/johnny0614/YJZAlbumCollectionViewLayout.git",
        "tag": "1.0.0"
    },
    "description": "YJZAlbumCollectionViewLayout is a UICollectionViewLayout subclass, used as the layout object of UICollectionView.nnThe idea of YJZAlbumCollectionViewLayout is inspired by RFQuiltLayout. The purpose of it is to allow users to create their desired collection layouts simply and straightforward.",
    "source_files": "YJZAlbumCollectionViewLayout",
    "platforms": {
        "ios": "6.0"
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This