purpose
I am trying to reduce the space between my UICollectionViewCells
What i tried
I tried to subclass UICollectionViewFlowLayout and override this method:
- (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
for(int i = 1; i < [answer count]; ++i) {
UICollectionViewLayoutAttributes *currentLayoutAttributes = answer[i];
UICollectionViewLayoutAttributes *prevLayoutAttributes = answer[i - 1];
NSInteger maximumSpacing = 4;
NSInteger origin = CGRectGetMaxX(prevLayoutAttributes.frame);
if(origin + maximumSpacing + currentLayoutAttributes.frame.size.width < self.collectionViewContentSize.width) {
CGRect frame = currentLayoutAttributes.frame;
frame.origin.x = origin + maximumSpacing;
currentLayoutAttributes.frame = frame;
}
}
return answer;
}
and then in my view UICollectionViewControllerDidLoad:
SublassedcollectionViewLayout *space = [[SublassedcollectionViewLayout alloc]init];
self.collectionView.collectionViewLayout = space;
Problem
It just reduces my UICollectionViewCells.
EDIT: I want to reduce the interval from left to right, not top to bottom.
Any help would be appreciated!
source
share