【发布时间】:2023-04-04 14:16:01
【问题描述】:
我想要一个水平滚动的集合视图,但我也希望它的顶部和右侧有一个标题。我已经尝试像实现垂直滚动的集合视图一样实现它,并且标题最终位于第一个单元格的左侧。
这是我如何使标头出队:
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let header = dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: identifier, for: indexPath) as! HeaderView
header.setWidth(to: headerWidth)
return header
}
标题大小:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: collectionView.frame.width, height: 12)
}
除此之外,我初始化的唯一其他属性是集合视图的滚动方向和插图
【问题讨论】:
-
至少显示你的代码
-
我对标题和
didEndDisplaying cell:使用了不同的视图。 -
要有水平,将集合的scrollDirection设置为horizontol
-
这意味着你不需要我认为的每个部分的标题,所以只需在 collectionView 上方放置一个 UILabel 就可以实现你的愿望。
标签: ios swift uicollectionview uicollectionviewcell