使用部分的 UICollectionView 在单元格之间留下间隙 [英] UICollectionView using sections leaves a gap between cells

查看:18
本文介绍了使用部分的 UICollectionView 在单元格之间留下间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UICollectionView 来显示多个数据部分.这些部分具有固定数量的项目.我希望所有项目都显示在一个连续的网格中.

I'm using a UICollectionView to show several sections of data. These sections have a fixed number of items. I want all the items to show in a continuous grid.

现在我在水平方向上完成了这个:

Right now I accomplish this in horizontal orientation:

但在垂直方面,这留下了很大的差距:

But in vertical this leaves a big gap:

我想解决部分之间的这个差距,因为它很丑而且不属于那里.我很乐意使用自定义 FlowLayout,但我找不到可以为我指明正确方向的教程(我找到了几个,但没有一个真正涉及到这个问题.)

I want to solve this gap between sections because it's ugly and it doesn't belong there. I'd be happy to use a custom FlowLayout, but I can't find a tutorial that points me in the right direction (I've found several, but none of them really touch this problem specifically.)

谁能帮我解决这个问题,或者至少给我指出正确的方向?

Can anybody help me solve this problem, or at least point me in the right direction?

P.S:我已经实现了部分,因为我正在动态加载数据.目前我无法选择使用 1 部分.

P.S: I've implemented sections because I'm loading the data on the fly. Using 1 section isn't an option for me at this moment.

更新根据要求,我正在添加用于我当前 FlowLayout 的值.我在全屏(减去 UINavigationBar)UICollectionView 上使用标准的水平流布局,每个部分有 21 个项目.

UPDATE On request I'm adding the values used for my current FlowLayout. I'm using the standard Horizontal Flow Layout on a fullscreen (minus UINavigationBar) UICollectionView with 21 items per section.

  • 滚动方向:水平
  • 像元大小:248、196
  • 页眉/页脚大小:无
  • 单元格的最小间距:10
  • 最小行间距:10
  • 部分插图:20、20、10、10

推荐答案

这样使用

解决Gap问题

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];

layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 2;

这篇关于使用部分的 UICollectionView 在单元格之间留下间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆