繁体   English   中英

如何在表格视图单元格内创建集合视图

[英]How to create collection view inside table view cell

如何在表格视图单元格内创建像这样具有不同单元格大小的集合视图以及在集合视图单元格图像内需要从 url 单元格下载如何在表格视图中创建像这样具有不同单元格大小的集合视图

我尝试了下面的代码,但最后 2 个小单元向上,并且当从 url 集合视图下载的图像直到手动触摸集合视图才加载时

 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let cVWidth = collectionView.frame.width
        let biggerCellWidth = (cVWidth / 2.5) - 5
        if indexPath.row == 2 || indexPath.row == 3 {
            let testValue:CGFloat = 3
            return CGSize(width: (biggerCellWidth / 2) - testValue  , height: (biggerCellWidth / 2) - testValue )
        }
        return CGSize(width: biggerCellWidth, height: biggerCellWidth)
    }

用于在表视图 go 到此链接中创建集合视图

UICollectionViewDelegateFlowLayout 里面有个方法

collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize

您可以在其中设置集合视图单元格大小的大小。 假设您要将第三个和第四个单元格的高度设置为集合视图的一半,大小为正方形。 把这个条件

if indexPath.row == 2 || indexPath.row == 3
{
    let height = collectionView.bounds.size.height / 2
    return CGSize(width: height, height: height)
}

暂无
暂无

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

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