简体   繁体   English

如何为UIcollectionView中的所有单元格设置不同的单元格大小

[英]How to different cell size for all the cells in UIcollectionView

I need to show the images in UICollectioview like link . 我需要像link一样在UICollectioview中显示图像。

How can i do this ? 我怎样才能做到这一点 ?

To represent items in a grid, you can use UICollectionViewFlowLayout . 要表示网格中的项目,可以使用UICollectionViewFlowLayout

But it won't work as expected with that large item that takes 2 rows.If you would like to have exactly the same layout, you should implement the UICollectionViewLayout subclass . 但这对于占用两行的大型项目将无法正常工作。如果您希望具有完全相同的布局,则应实现UICollectionViewLayout 子类

您可以使用名为Waterfall Layout的存储库来完成此操作,然后使用以下功能:

func collectionView (collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize 

May be this help. 可能是这个帮助。

https://www.cocoacontrols.com/controls/nhbalancedflowlayout https://www.cocoacontrols.com/controls/nhbalancedflowlayout

This is a open source project named as NHBalancedFlowLayout in Objective-c. 这是一个在Objective-c中名为NHBalancedFlowLayout的开源项目。

In this they have customized the UICollectionViewLayout for displaying items of different sizes in a grid. 他们为此定制了UICollectionViewLayout以在网格中显示不同大小的项目。

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

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