gpt4 book ai didi

ios - Swift 4 - Collection View 将节插入应用于标题?

转载 作者:行者123 更新时间:2023-11-29 05:38:06 25 4
gpt4 key购买 nike

我正在使用 Collection View ,并且可以将部分插入添加到 Collection View 内的单元格,但它似乎不适用于 Collection View 可重用 View ,是否可以为可重用 View 设置部分插入?

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()

}

最佳答案

首先,让我们明确一下节插入到底是什么。

Section insets are margins applied only to the items in the section. They represent the distance between the header view and the first line of items and between the last line of items and the footer view. They also indicate the spacing on either side of a single line of items. They do not affect the size of the headers or footers themselves.

以下是如何在 collectionView 中添加 sectioninsets

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

关于ios - Swift 4 - Collection View 将节插入应用于标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56829943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com