がありUICollectionViewController
、カスタムヘッダーを追加したいと思います。
Section Header
CollectionViewController内のInterfaceBuilderをチェックインし、そのサブクラスに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内の通常のセルと重なるようになりました。
私は何が間違っているのですか?助けに感謝します!
public func layoutAttributesForSupplementaryElementOfKind(kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes?
ここでフレーム/高さを設定できるはずだと思います
ありますheaderReferenceSize
でUICollectionViewFlowLayout
、あなたの作成時に設定することができcollectionView
、静的なことになるだろう場合
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加