简体   繁体   English

如何设置集合视图单元格在单行中两个单元格之间没有间隙

[英]How to set collection view cell without gap between two cell in single row

I placed one collection view with one custom cell using storyboard.Totally i have 6 images so per row i have 2 images ( 2 cell).Now when i run the gap between 2 cells is much more.i need to remove all gap between all cells so how it should look like is without gap having 6 images .Now below image is what i need to remove gap 我使用情节提要放置了一个具有一个自定义单元格的集合视图。总共我有6张图像,所以每行我有2张图像(2个单元格)。现在当我在2个单元格之间运行时,间隙要大得多。我需要消除所有之间的间隙单元格,所以它看起来应该是没有6张图像的间隙。现在下面的图像是我需要消除间隙的图像 在此处输入图片说明

I try to increase the width of cell using story board. 我尝试使用故事板增加单元的宽度。 But i doesn't work. 但是我不工作。 Is there any idea to get with out gap between each cell in all rows ( right, top, bottom gap between all cells ) 有没有什么想法可以消除所有行中每个单元格之间的间隙(所有单元格之间的右,上,下间隙)

Please help me out.Thanks 请帮帮我。谢谢

But when i run in iphone 6, i am getting like this , why?? 但是当我在iPhone 6上运行时,我会变成这样,为什么? 在此处输入图片说明

Make your class conform to UICollectionViewDelegateFlowLayout protocol and implement the methods: 使您的类符合UICollectionViewDelegateFlowLayout协议并实现以下方法:

- (CGSize)collectionView:(UICollectionView *)collectionView
              layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

    CGFloat width = self.collectionView.frame.size.width/2;
    return CGSizeMake(width, width);
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {

   return UIEdgeInsetsZero;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {

   return 0.0;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
   return 0.0;
}

You can set the minimumInteritemSpacing in the UICollectionViewFlowLayout, here in the documentation you can see more details 您可以在minimumInteritemSpacing中设置minimumInteritemSpacing,在此处的文档中您可以查看更多详细信息

Like this, 像这样,

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInterItemSpacing = 1;

self.collectionView.layout = flowLayout;

Source : http://nsscreencast.com/episodes/46-fun-with-uicollectionview 来源: http : //nsscreencast.com/episodes/46-fun-with-uicollectionview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM