相关疑难解决方法(0)

如何水平居中UICollectionView细胞?

我做了一些研究,但是我找不到任何关于如何在UICollectionView中水平居中单元格的代码示例.

而不是第一个单元格像这个X00,我希望它像这个0X0.有没有办法实现这个目标?

编辑:

想象我想要的东西:

在此输入图像描述

当CollectionView中只有一个元素时,我需要它看起来像版本B. 当我有多个元素时,它应该像版本A但有更多元素.

当我只有1个元素时,它看起来像版本A,我想知道我怎么能让它看起来像B.

谢谢您的帮助!

ios swift

107
推荐指数
10
解决办法
7万
查看次数

How to center align the cells of a UICollectionView?

I am currently using UICollectionView for the user interface grid, and it works fine. However, I'd like to be enable horizontal scrolling. The grid supports 8 items per page and when the total number of items are, say 4, this is how the items should be arranged with horizontal scroll direction enabled:

0 0 x x
0 0 x x
Run Code Online (Sandbox Code Playgroud)

Here 0 -> Collection Item and x -> Empty Cells

有没有办法使它们居中对齐,如:

x 0 0 x
x 0 0 x
Run Code Online (Sandbox Code Playgroud)

这样内容看起来更干净? …

ios uicollectionview

96
推荐指数
11
解决办法
9万
查看次数

标签 统计

ios ×2

swift ×1

uicollectionview ×1