Objective
I am trying to decrease the space between my UICollectionViewCells
What I tried
I tried subclassing UICollectionViewFlowLayout and overriding 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 UICollectionViewController viewDidLoad:
SublassedcollectionViewLayout *space = [[SublassedcollectionViewLayout alloc]init];
self.collectionView.collectionViewLayout = space;
Problem
That just makes my UICollectionViewCells smaller.
EDIT: I want to decrease the spacing from left to right instead of top to bottom.
Any help will be appreciated!