自定义UICollectionViewLayout的问题在单元格的底部留下间隙

时间:2017-09-16 14:04:05

标签: swift uicollectionviewlayout

我有一个带有自定义布局的UICollectionView。如下图所示,内容与单元底部之间始终存在间隙。

enter image description here

每个单元格由一个图像和三个标签组成。我打印出了单元格的大小,并打印出图像的大小+ 3个标签和匹配,所以我不知道这个额外的空间来自哪里。

    let width = columnWidth - cellPadding*2
    let photoHeight = delegate.collectionView(collectionView!, heightForPhotoAtIndexPath: indexPath , withWidth:width)
                print("photo height is: \(photoHeight)")//photo height is: 95.4078125            

    let label1Height = delegate.collectionView(collectionView!, heightForLabel1AtIndexPath: indexPath, withWidth: width)
               print("label1Height is \(label1Height)") // label1Height is 39.0            

    let label2Height = delegate.collectionView(collectionView!,heightForLabel2AtIndexPath: indexPath, withWidth: width) //label2Height is 53.0            
               print("label2Height is \(label2Height)")// label2Height is 53.0       
    let label3Height = delegate.collectionView(collectionView!, heightForLabel3AtIndexPath: indexPath, withWidth: width)

                print("label3Height is \(label3Height)") //label3Height is 135.0            

    let height = photoHeight + label1Height + label2Height + label3Height
                print("total height is: \(height)") //total height is: 322.4078125            

    let frame = CGRect(x: xOffset[column], y: yOffset[column], width: columnWidth, height: height)
                let insetFrame = frame.insetBy(dx: cellPadding, dy: cellPadding)

我已将label3的底部固定在单元格的底部+4,但这没有帮助

0 个答案:

没有答案