diff --git a/CHTCollectionViewWaterfallLayout.h b/CHTCollectionViewWaterfallLayout.h index 5d3d4a8..b97f585 100644 --- a/CHTCollectionViewWaterfallLayout.h +++ b/CHTCollectionViewWaterfallLayout.h @@ -186,6 +186,28 @@ extern NSString *const CHTCollectionElementKindSectionFooter; */ - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section; + +/** + * Asks the delegate for the minimum spacing between colums in a secified section. If this method is not implemented, the + * minimumColumnSpacing property is used for all sections. + * + * @param collectionView + * The collection view object displaying the waterfall layout. + * @param collectionViewLayout + * The layout object requesting the information. + * @param section + * The index of the section whose minimum interitem spacing is being requested. + * + * @discussion + * If you do not implement this method, the waterfall layout uses the value in its minimumColumnSpacing property to determine the amount of space between columns in each section. + * + * @return + * The minimum spacing between each column. + */ +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumColumnSpacingForSectionAtIndex:(NSInteger)section; + + + @end #pragma mark - CHTCollectionViewWaterfallLayout diff --git a/CHTCollectionViewWaterfallLayout.m b/CHTCollectionViewWaterfallLayout.m index f754c0f..d6561bb 100644 --- a/CHTCollectionViewWaterfallLayout.m +++ b/CHTCollectionViewWaterfallLayout.m @@ -119,7 +119,13 @@ - (CGFloat)itemWidthInSectionAtIndex:(NSInteger)section { } CGFloat width = self.collectionView.frame.size.width - sectionInset.left - sectionInset.right; NSInteger columnCount = [self columnCountForSection:section]; - return CHTFloorCGFloat((width - (columnCount - 1) * self.minimumColumnSpacing) / columnCount); + + CGFloat columnSpacing = self.minimumColumnSpacing; + if ([self.delegate respondsToSelector:@selector(collectionView:layout:minimumColumnSpacingForSectionAtIndex:)]){ + columnSpacing = [self.delegate collectionView:self.collectionView layout:self minimumColumnSpacingForSectionAtIndex:section]; + } + + return CHTFloorCGFloat((width - (columnCount - 1) * columnSpacing) / columnCount); } #pragma mark - Private Accessors @@ -240,6 +246,11 @@ - (void)prepareLayout { } else { minimumInteritemSpacing = self.minimumInteritemSpacing; } + + CGFloat columnSpacing = self.minimumColumnSpacing; + if ([self.delegate respondsToSelector:@selector(collectionView:layout:minimumColumnSpacingForSectionAtIndex:)]){ + columnSpacing = [self.delegate collectionView:self.collectionView layout:self minimumColumnSpacingForSectionAtIndex:section]; + } UIEdgeInsets sectionInset; if ([self.delegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]) { @@ -250,7 +261,7 @@ - (void)prepareLayout { CGFloat width = self.collectionView.frame.size.width - sectionInset.left - sectionInset.right; NSInteger columnCount = [self columnCountForSection:section]; - CGFloat itemWidth = CHTFloorCGFloat((width - (columnCount - 1) * self.minimumColumnSpacing) / columnCount); + CGFloat itemWidth = CHTFloorCGFloat((width - (columnCount - 1) * columnSpacing) / columnCount); /* * 2. Section header @@ -299,7 +310,7 @@ - (void)prepareLayout { for (idx = 0; idx < itemCount; idx++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx inSection:section]; NSUInteger columnIndex = [self nextColumnIndexForItem:idx inSection:section]; - CGFloat xOffset = sectionInset.left + (itemWidth + self.minimumColumnSpacing) * columnIndex; + CGFloat xOffset = sectionInset.left + (itemWidth + columnSpacing) * columnIndex; CGFloat yOffset = [self.columnHeights[section][columnIndex] floatValue]; CGSize itemSize = [self.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath]; CGFloat itemHeight = 0;