Last active
August 29, 2015 14:22
-
-
Save BradB132/2a5a593279fd99e55b4f to your computer and use it in GitHub Desktop.
GettingStartedWithCustomUICollectionViewLayouts-3
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
-(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect | |
{ | |
NSMutableArray* elementsInRect = [NSMutableArray array]; | |
//iterate over all cells in this collection | |
for(NSUInteger i = 0; i < [self.collectionView numberOfSections]; i++) | |
{ | |
for(NSUInteger j = 0; j < [self.collectionView numberOfItemsInSection:i]; j++) | |
{ | |
//this is the cell at row j in section i | |
CGRect cellFrame = CGRectMake(/* calculate your origin x */, | |
/* calculate your origin y */, | |
/* calculate your width */, | |
/* calculate your height */); | |
//see if the collection view needs this cell | |
if(CGRectIntersectsRect(cellFrame, rect)) | |
{ | |
//create the attributes object | |
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:j inSection:i]; | |
UICollectionViewLayoutAttributes* attr = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; | |
//set the frame for this attributes object | |
attr.frame = cellFrame; | |
[elementsInRect addObject:attr]; | |
} | |
} | |
} | |
return elementsInRect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment