Space between UICollectionViewCell rows

五迷三道 提交于 2019-12-11 04:08:44

问题


Currently I have a 9 items displayed in my collection. I want a 3*3 grid for each section I have. So when I want to go to the next section I scroll to the right and and I see the 3*3 grid for my next section. What I did to accomplish this was setting the height of the UICollection to 3*height_of_my_cell. I also made sure that:

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

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

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

So the goal is really to have the cells pasted to each other (no space between them). The problem is that what I am getting is this:

To see the 7,8 and 9 I need to scroll to the right. So I see that I am able to get rid of the space between the "columns" but not the rows. So do I need o create a custom UICollectionViewFlowLayout to achieve this? Also this is being done on iOS7, which I am not sure if it might influence the final result.


回答1:


Just set the property of UICollectionViewFlowLayout, such as:

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 0;




回答2:


Was able to solve the issue, by creating a custom UICollectionViewFlowLayout and adding this line:

[self setSectionInset:UIEdgeInsetsMake(-65.0f, 1.0f, 0.0f, 0.0f)];



来源:https://stackoverflow.com/questions/18818099/space-between-uicollectionviewcell-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!