Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove space between cells in UICollectionView? [duplicate]

How to remove space between two cells in UiCollectionView? Min spacing is not working.

image

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (collectionView.tag==101)
    {
        return CGSizeMake((_collView.frame.size.width),(_collView.frame.size.height));

    }
    else
    {
       return CGSizeMake((_collView2.frame.size.width/3)-20,300);
    }
}

But this is not working.

like image 574
kartik patel Avatar asked Jul 13 '17 18:07

kartik patel


Video Answer


2 Answers

*enter image description here *

Set Min Spacing for cells and for Lines to Zero and replace your code by

- (CGSize)collectionView:(UICollectionView *)collectionView layout:       (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:   (NSIndexPath *)indexPath
{
if (collectionView.tag==101)
{
    return CGSizeMake((_collView.frame.size.width),(_collView.frame.size.height));
}
else
{
   return CGSizeMake((_collView2.frame.size.width/3),300);
}
 }
like image 88
Vikky Avatar answered Sep 17 '22 19:09

Vikky


Use UICollectionViewFlowLayout for those purposes:

UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
flow.itemSize = CGSizeMake(cellWidth, cellHeight);
flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
flow.minimumInteritemSpacing = 0;
flow.minimumLineSpacing = 0;
like image 32
Vasilii Muravev Avatar answered Sep 19 '22 19:09

Vasilii Muravev