Swift 4-集合视图将节插图应用于标题吗?

时间:2019-07-01 04:16:15

标签: ios swift

我正在使用“集合视图”,并且能够将“节”插图添加到“集合”视图内的单元格中,但是它似乎不适用于“集合视图”的可重用视图,是否可以为可重复使用的视图设置节插图?

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {


        if(kind == UICollectionView.elementKindSectionFooter)
        {
            let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "ReviewsFooter", for: indexPath) as! ReviewFooterCell

            footerView.reviewFooterDelegate = self

            return footerView
        }
        else if(kind == UICollectionView.elementKindSectionHeader)
        {
            let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "ReviewHeader", for: indexPath) as! ReviewHeaderCell

            headerView.totalReviews.text = "Total Reviews: " + String(self.reviews.count)

            return headerView
        }

        fatalError()

    }

1 个答案:

答案 0 :(得分:0)

首先,让我们弄清楚究竟是什么节插图

  

节插图是仅应用于节中项目的边距。   它们代表标题视图和第一行之间的距离   项以及在最后一行和页脚视图之间。他们   还要指出单行项目两侧的间距。   它们不会影响页眉或页脚本身的大小。

这里是如何在insets中添加section中的collectionView

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    return UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
}
相关问题