【发布时间】:2016-11-18 13:26:48
【问题描述】:
我有一个UICollectionViewController 并想添加一个自定义标题。
我在 CollectionViewController 的 Interface Builder 中检查了Section Header,并在我的子类中实现了viewForSupplementaryElementOfKind 函数。
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionHeader:
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "myHeaderIdentifier", for: indexPath)
// !! NOT WORKING PROPERLY
// sectionHeader overlaps other cells
headerView.backgroundColor = UIColor(hue: 0.9, saturation: 1.0, brightness: 0.9, alpha: 1.0)
headerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 250.0)
return headerView
default:
assert(false, "Unexpected element kind")
}
}
更改生效,但标题(下面屏幕截图中的粉红色区域)现在与 collectionView 中的常规单元格重叠。
我做错了什么? 感谢任何帮助!
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell uicollectionreusableview