0
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    
    
    if collectionView == self.collectionViewVideo {

        var collectionViewSize = collectionViewVideo.frame.size
        collectionViewSize.width = collectionViewSize.width/3.0 //Display Three elements in a row.
        return collectionViewSize
    } else {
        return CGSize(width: 60, height: 60)
    }
    
    
}

我想像这样展示我的收藏视图

4

1 回答 1

4

您还需要考虑空间。空间是您的收藏视图项目空间

以下是代码有两个单元格和 20 个空格。(我没有写你需要的代码你应该自己做)

extension YourViewController : UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 20
    }

    //--------------------------------------------------------------------------------

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 20;
    }

    //--------------------------------------------------------------------------------

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: ( self.collectionView.frame.size.width - 60 ) / 2,height:( self.collectionView.frame.size.width - 60 ) / 2)
    }

    //--------------------------------------------------------------------------------

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
       return UIEdgeInsetsMake(0, 20, 20, 20)
    }
}

这里 60 指的是SPACE 20 CELL SPACE 20 CELL SPACE 20

于 2018-04-12T12:00:46.557 回答