SkillAgentSearch skills...

YJZAlbumCollectionViewLayout

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

Install / Use

/learn @johnny0614/YJZAlbumCollectionViewLayout
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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;

Related Skills

View on GitHub
GitHub Stars19
CategoryDevelopment
Updated8y ago
Forks1

Languages

Objective-C

Security Score

75/100

Audited on May 30, 2017

No findings