Reduce the space between UICollectionViewCells

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!

0
source share
1 answer

VERTICAL SPACE

Select the type of collection in the storyboard.

Then change ...

enter image description here

Change

enter image description here

For

enter image description here

,

, , . , 0 x,

enter image description here

enter image description here

:

enter image description here

enter image description here

, () , . .

, , ,

+6

Source: https://habr.com/ru/post/1546356/


All Articles