在UICollectionView中显示一行-Swift [英] Display one row in UICollectionView - Swift
问题描述
我试图弄清楚如何限制UICollectionView在单个行中显示水平可滚动列表.
I'm trying to figure out how to limit a UICollectionView to display a horizontal scrollable list in a single row.
有什么想法吗?
推荐答案
我刚刚使用了对我有用的东西:
I just used something that is working for me:
- 将滚动方向"设置为水平".
- 使用
sizeForItemAt indexPath
方法设置Cell
的大小. - 为您的
CollectionView
设置一个约束,使其高度等于(或稍大于)您在上面指定的Cell
的高度.
- Set the Scroll direction to Horizontal.
- Set the size of your
Cell
s usingsizeForItemAt indexPath
method. - Set a constraint to your
CollectionView
making its height equal to (or a bit greater than) theCell
's height which you specified above.
其背后的逻辑:
当 CollectionView
的高度等于其 item
的高度并将其设置为水平滚动时,则只能将它们显示为一个行
.我说或比 cell
的高度大一点"是因为如果您将 CollectionView
的高度设置为比 cell
的高度大两倍那么它可以容纳两行 cell
,并且将它们显示为两行,而不是一列.
When the height of CollectionView
is equal to the height of it's item
s and it is set to horizontal scroll, then it can only show them in one row
. I said "or a bit greater than cell
's height" because if you set the height of your CollectionView
twice bigger than cell
's height then it can fit 2 rows of cell
s and it will show them in 2 rows instead of one.
这篇关于在UICollectionView中显示一行-Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!