Latest 2.0
License MIT
Platforms ios 7.0, requires ARC

The standard available UICollectionViewLayout does the job well, but the UI may look asymmetric, depending on the number of items the UICollectionView is displaying. This library attempts to solve this problem. This is a UICollectionViewLayout subclass that fills the full width of the collection view.


CocoaPods is the preferred way to install this library. Add this command to your Podfile:

pod 'ASJCollectionViewFillLayout'

If you prefer the classic way, just copy the ASJCollectionViewFillLayout folder (.h and .m files) to your project.


Creating an ASJCollectionViewFillLayout is easy. It has a simple interface consisting of three properties. You can also use the traditional delegate pattern to return the attributes you wish to use. All are optional.

@property (assign, nonatomic) NSInteger numberOfItemsInSide;

Sets the number of items to show in one row or column, depending on the layout’s direction property.

@property (assign, nonatomic) CGFloat itemLength;

Sets the width or height of an item, depending on the layout’s direction property. For vertical direction, this sets the item height and for horizontal direction, this sets the item width.

@property (assign, nonatomic) CGFloat itemSpacing;

Sets the distance between two collection view items.

@property (assign, nonatomic) ASJCollectionViewFillLayoutDirection direction;

Sets the direction in which the collection view items are laid out. Valid options are ASJCollectionViewFillLayoutVertical and ASJCollectionViewFillLayoutHorizontal. Defaults to ASJCollectionViewFillLayoutVertical.

@property (assign, nonatomic) BOOL stretchesLastItems;

Sets whether the last items should be stretched to occupy the full width of the UICollectionView. Defaults to YES.

For example:

ASJCollectionViewFillLayout *aFillLayout = [[ASJCollectionViewFillLayout alloc] init];
aFillLayout.numberOfItemsInRow = 3;
aFillLayout.itemSpacing = 5.0f;
aFillLayout.itemHeight = 75.0f;
aFillLayout.stretchesLastItems = NO;
aCollectionView.collectionViewLayout = aFillLayout;

See the example project for a demonstration of how to use the delegate pattern.

alt tag
alt tag



  • Handle case of total collection view items being less than the number of items in one row.
  • Add option for horizontal direction; try subclassing UICollectionViewFlowLayout itself.


ASJCollectionViewFillLayout is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "ASJCollectionViewFillLayout",
    "version": "2.0",
    "platforms": {
        "ios": "7.0"
    "license": {
        "type": "MIT"
    "homepage": "",
    "authors": {
        "Sudeep Jaiswal": "[email protected]"
    "summary": "A flow layout style UICollectionViewLayout that fills the full width of the collection view",
    "source": {
        "git": "",
        "tag": "2.0"
    "source_files": "ASJCollectionViewFillLayout/*.{h,m}",
    "requires_arc": true

Pin It on Pinterest

Share This