简体   繁体   English

在集合视图中显示长单元格(如矩形)的问题

[英]Issue with displaying a long cell(like a rectangle) in a collection view

I want to display a collection view image which looks like so... 我想显示一个看起来像这样的收藏夹视图图像...

在此处输入图片说明

Here, as you can see the whole cell is of a rectangle shape with space for text and buttons below the image. 在这里,您可以看到整个单元格是一个矩形,在图像下方有文本和按钮的空间。 I am not able to load such a 'rectangle' shaped cell in my collectioview. 我无法在collectioview中加载这种“矩形”形状的单元格。 Any help would be appreciated. 任何帮助,将不胜感激。

Thanks in advance...:) 提前致谢...:)

To set the size of item of a collectionview you can implement this UICollectionViewDelegateFlowLayout method 要设置collectionview的项目大小,可以实现此UICollectionViewDelegateFlowLayout方法

func collectionView(_ collectionView: UICollectionView,
                    layout collectionViewLayout: UICollectionViewLayout,
                    sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: 30, height: 100)
}

Your question is not very clear as it does not show your code or what result you got. 您的问题不是很清楚,因为它没有显示您的代码或您得到了什么结果。 But it is quiet simple For customising cell size use below code and pass width and height accordingly 但这很简单,要自定义单元格大小,请使用以下代码,并相应地传递宽度和高度

func collectionView(_ collectionView: UICollectionView,
                layout collectionViewLayout: UICollectionViewLayout,
                sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: accordingly to your requirement, height: accordingly to your requirement)

} }

Please check this link which can explain every bit in detail. 请检查此链接,该链接可以详细说明每一点。 And play with different value to get your required result. 并发挥不同的价值,以获得所需的结果。

Custom cell collectionview 自定义单元格集合视图

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

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