Collectionview edgeInsets错误

时间:2017-01-04 09:50:50

标签: ios swift xcode swift3

enter image description here

我该怎么办?我想改变一行边缘。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {

    if  indexPath.row == 8{
        return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
    }
    return UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 0)
}

1 个答案:

答案 0 :(得分:1)

collectionView:layout:insetForSectionAt:函数不设置单元格的插入,而是设置单元格所在的部分。因此您不想使用indexPath.row,因为它与此无关功能,因此不存在。它提供section参数,该参数与该函数相关。

section参数将包含与您发布的其他函数中的indexPath.section对应的值。