小编Eri*_*uan的帖子

如何水平居中调整大小的 UICollectionView 单元格?

我有一个 collectionView 并且方向设置为 Horizo​​ntal 并且每个单元格只包含一个 UIlabel 并且它使用自动布局来确定单元格的宽度。

例如,有三个单元格,这是默认行为。

|[x] [xxx] [xxxxxxxxx] |

但是如果所有单元格的总宽度不超过屏幕的宽度,则要求将这三个单元格居中对齐。

第一个单元格的左插图应该是

leftInset = (screen width - (first cell width + second cell width + third cell width + total spaces between the three cells) /) 2

结果是

| [x] [xxx] [xxxxxxxxx] |

我从如何水平居中 UICollectionView 单元格中找到了固定宽度单元格的一个很好的答案,但不适用于自尺码。

如果您愿意提供帮助,我们将不胜感激。

ios autolayout uicollectionview swift

5
推荐指数
1
解决办法
820
查看次数

标签 统计

autolayout ×1

ios ×1

swift ×1

uicollectionview ×1