简体   繁体   English

UICollectionView流布局问题

[英]UICollectionView flow layout issue

I want to implement a collection view(scroll vertically) layout like the left of the following image. 我想实现一个集合视图(垂直滚动)布局,如下图所示。 But when I use UICollectionViewFlowLayout, it looks like the right one. 但是,当我使用UICollectionViewFlowLayout时,它看起来像是正确的。 So is it possible to achieve this with flow layout, or I need to look into custom layout? 那么可以使用流布局来实现这一点,还是我需要研究自定义布局? Thanks in advance! 提前致谢!

在此处输入图片说明

You need a custom layout. 您需要自定义布局。 The flow layout will arrange items in rows, then break onto the next row when it runs out of width, as you're seeing there. 流布局将按行排列项目,然后在宽度用尽时中断到下一行,如您所见。

There are plenty of "waterfall" style layouts available online, such as this one which I've used a couple of times. 有很多可用的“瀑布”式布局在线,如这一个 ,我已经使用了好几次。 You need to set a consistent column width and number of columns for these, though - I can't tell from your drawing if that is the case. 不过,您需要为此设置一致的列宽和列数-我无法从您的图形中得知是否是这种情况。

您可以创建自定义UICollectionViewLayout ,我发现本教程非常有用: 自定义布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM