UICollectionViewCell Spacing设置为0但仍具有间距(UICollectionViewCell Spacing is set to 0 but still have spaci

编程入门 行业动态 更新时间:2024-10-28 20:20:54
UICollectionViewCell Spacing设置为0但仍具有间距(UICollectionViewCell Spacing is set to 0 but still have spacing)

我试图让我的单元格之间的间距= 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.

更多推荐

本文发布于:2023-07-22 03:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1216702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间距   设置为   但仍   Spacing   UICollectionViewCell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!