我试图让我的单元格之间的间距= 0
期望结果的示例:
我现在拥有的东西(iPhone 6):
我的代码:
- (UICollectionViewFlowLayout *)setCollectionViewFlowLayout { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; //iphone5 100 //iphone6 118 layout.itemSize = CGSizeMake(118, 118); layout.footerReferenceSize = CGSizeMake(0, 0); layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.minimumInteritemSpacing = 0.0; layout.minimumLineSpacing = 0.0; return layout; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0, 0, 0, 0); }我在IB上有什么:
我错过了什么? 提前致谢!
I am trying to make the spacing between my cells = 0
Example of desired result:
What I currently have (iPhone 6):
My code:
- (UICollectionViewFlowLayout *)setCollectionViewFlowLayout { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; //iphone5 100 //iphone6 118 layout.itemSize = CGSizeMake(118, 118); layout.footerReferenceSize = CGSizeMake(0, 0); layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.minimumInteritemSpacing = 0.0; layout.minimumLineSpacing = 0.0; return layout; } - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0, 0, 0, 0); }What I have on IB:
What am I missing? Thanks in advance!
最满意答案
如果未设置,请更新您的cellsize和imageview大小。 你必须设置你的imageview的约束适合单元格。
更换
layout.itemSize = CGSizeMake(118, 118);同
layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width /3, [UIScreen mainScreen].bounds.size.width /3);我设置屏幕大小,因为我假设你的collectionview适合屏幕宽度。 将其替换为您的collectionview大小。
因为您尝试显示3个单元格,但您为项目设置了固定宽度。 所以只需更新您的单元格大小。 因为在不同的屏幕中,您的集合视图将会发生变化,因此您也应该更新单元格大小。
update your cellsize and imageview size if you didn't set. you have to set your imageview's constraint fit with cell.
replace
layout.itemSize = CGSizeMake(118, 118);with
layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width /3, [UIScreen mainScreen].bounds.size.width /3);I set screensize because i assume your collectionview is fit to screen width. replace it with your collectionview size.
Because you are trying to show 3 cells but you set fix width for your item. so just update your cell size. Because in different screen your collectionview widht will be change so you should update your cell size also.
更多推荐
发布评论