Skip to content

UICollectionViewLayout subclass for displaying items of different sizes in a grid without wasting any visual space. Inspired by: http://www.crispymtn.com/stories/the-algorithm-for-a-perfectly-balanced-photo-gallery

License

Notifications You must be signed in to change notification settings

graetzer/NHBalancedFlowLayout

 
 

Repository files navigation

NHBalancedFlowLayout

UICollectionViewLayout subclass for displaying items of different sizes in a grid without wasting any visual space. Inspired by: http://www.crispymtn.com/stories/the-algorithm-for-a-perfectly-balanced-photo-gallery

About this Fork

Mainly three differences to the original:

  • It fixes the Issue of upscaled images wich occurs if the partition algorithm assigns a single item to one row.
  • Incorporates a fix for a crash on [UICollectionView insertSections:] from Pull Request #24
  • It implements swipe in and out animations, when inserting or removing cells.

Hopefully this can be useful for some of you, if you don't want the animations you can easily remove them in the code: piece 1 and piece 2.

Notes

  • Tested with iOS 7, but should be compatible with iOS6 as well
  • Works with iPhone and iPad
  • All interface orientations are supported

Screenshots

Installation

The easiest way is to use CocoaPods. If you don't already, here's a guide.

pod 'NHBalancedFlowLayout', '~> 0.2'

If you don't use CocoaPods, you'll need to copy the following files into your project:

  • NHBalancedFlowLayout.h
  • NHBalancedFlowLayout.m
  • NHLinearPartition.h
  • NHLinearPartition.m

Credits

Attributions for the photos in the same order as they appear in the demo:

About

UICollectionViewLayout subclass for displaying items of different sizes in a grid without wasting any visual space. Inspired by: http://www.crispymtn.com/stories/the-algorithm-for-a-perfectly-balanced-photo-gallery

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 98.2%
  • Ruby 1.8%