Skip to content

Instantly share code, notes, and snippets.

@nicksnyder
Last active January 25, 2019 11:39
Show Gist options
  • Save nicksnyder/4075682 to your computer and use it in GitHub Desktop.
Save nicksnyder/4075682 to your computer and use it in GitHub Desktop.
// Created by Nick Snyder on 11/13/12.
// https://gist.github.com/nicksnyder/4075682
// http://stackoverflow.com/questions/12927027/uicollectionview-flowlayout-not-wrapping-cells-correctly-ios
// NDCollectionViewFlowLayout.h
@interface NDCollectionViewFlowLayout : UICollectionViewFlowLayout
@end
// Created by Nick Snyder on 11/13/12.
// https://gist.github.com/nicksnyder/4075682
// http://stackoverflow.com/questions/12927027/uicollectionview-flowlayout-not-wrapping-cells-correctly-ios
// NDCollectionViewFlowLayout.m
#import "NDCollectionViewFlowLayout.h"
@implementation NDCollectionViewFlowLayout
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
NSMutableArray *newAttributes = [NSMutableArray arrayWithCapacity:attributes.count];
for (UICollectionViewLayoutAttributes *attribute in attributes) {
if ((attribute.frame.origin.x + attribute.frame.size.width <= self.collectionViewContentSize.width) &&
(attribute.frame.origin.y + attribute.frame.size.height <= self.collectionViewContentSize.height)) {
[newAttributes addObject:attribute];
}
}
return newAttributes;
}
@end
@appleramos
Copy link

How can I implement this? I already made this and it is not called. Where should I call this? Thanks in advance

@narendrabade
Copy link

How can I implement this? I already made this and it is not called. Where should I call this? Thanks in advance

@User2004
Copy link

Click here for set collectionview flow layout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment