Skip to content

With this UICollectionViewFlowLayout subclass, your UICollectionView looks like a UITableView if you are using cells with dynamic heights.

License

Notifications You must be signed in to change notification settings

yoeriboven/TopAlignedCollectionViewLayout

Repository files navigation

TopAlignedCollectionViewLayout

With this UICollectionViewFlowLayout subclass, your UICollectionView looks like a UITableView if you are using cells with dynamic heights.

If items on a row have different heights, the row will get the same height as the biggest item on the row. The smaller items will then center on the y-axis. With YBTopAlignedCollectionViewFlowLayout, all items will be aligned at the top.

Gif example.

How to use

Using YBTopAlignedCollectionViewFlowLayout is very easy:

Add the pod YBTopAlignedCollectionViewFlowLayout to your Podfile or manually download the files and add them to your project.

#import "YBTopAlignedCollectionViewFlowLayout.h"

Now where you would create the UICollectionViewFlowLayout do this:

YBTopAlignedCollectionViewFlowLayout *layout = [[YBTopAlignedCollectionViewFlowLayout alloc] initWithNumColumns:3];
layout.delegate = self;

Don't forget to implement the delegate.

@interface MyViewController : UIViewController <UICollectionViewDelegateFlowLayout>

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;

Requirements

YBTopAlignedCollectionViewFlowLayout requires iOS 6.0 or greater.

The example project only works with iOS 7

License

Usage is provided under the MIT License. See LICENSE for the full details.

About

With this UICollectionViewFlowLayout subclass, your UICollectionView looks like a UITableView if you are using cells with dynamic heights.

Resources

License

Stars

Watchers

Forks

Packages

No packages published