Last active
January 25, 2019 11:39
-
-
Save nicksnyder/4075682 to your computer and use it in GitHub Desktop.
Fix rendering bug in UICollectionViewFlowLayout as described here:
http://stackoverflow.com/questions/12927027/uicollectionview-flowlayout-not-wrapping-cells-correctly-ios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I implement this? I already made this and it is not called. Where should I call this? Thanks in advance