CollectionView中每个单元格的自定义位置

时间:2017-01-30 12:23:59

标签: ios swift uicollectionview

我目前正在使用带有自定义xib的UICollectionView来重新创建它 mockup

使用sizeForItemAtIndexPath委托方法,我可以更改每个UICollectionViewCell的尺寸:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let screenSize = UIScreen.mainScreen().bounds
    let screenWidth = screenSize.width
    let screenHeight = screenSize.height
    let customHeight = screenHeight / 7

    if indexPath.row == 2{
        return CGSizeMake(screenWidth / 3, customHeight * 2);
    }
    if indexPath.row == 6{
        return CGSizeMake(screenWidth, customHeight * 2);
    }

    return CGSizeMake(screenWidth / 3, customHeight);
}

这就是我得到的:

enter image description here

所以我无法将前两个图像的y更改为顶部,并在底部添加两个图像(就像在样机中一样)。

0 个答案:

没有答案
相关问题