调整UICollectionView中特定部分的插图

Gau*_*rma 4 ios uicollectionview uicollectionviewlayout uicollectionviewdelegate swift

  1. insetForSectionAtIndex(在DelegateFlowLayout上)使您可以为节中的所有单元格设置插入

  2. sectionInset(在FlowLayout上)使您可以设置适用于所有部分的插图。

但是,我正在寻找一种仅将插页应用于一个特定部分的方法-这可能吗?

pab*_*ros 5

您必须UICollectionViewDelegateFlowLayout使用以下方法来实现您的类:

对于Swift 4

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

    var edgeInsets = UIEdgeInsets()
    if section == THE_SECTION_YOU_WANT {
        // edgeInsets configuration stuff
    }

    return edgeInsets;
}
Run Code Online (Sandbox Code Playgroud)

对于Swift 3

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

    var edgeInsets = UIEdgeInsets()
    if section == THE_SECTION_YOU_WANT {
        // edgeInsets configuration stuff
    }

    return edgeInsets;

}
Run Code Online (Sandbox Code Playgroud)