insetForSectionAtIndexメソッドを使用して、コレクションビューのセクションのcontentInsetを設定しましたが、そのインセットをセクションのヘッダーに適用しません。ヘッダーの幅は画面の幅と同じにする必要があります。異なるコンテンツを適用する方法コンテンツセルに対してのみUICollectionViewのヘッダーではなくコンテンツセルにのみ適用します
ConentInset
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
if section == 1 {
return UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 15)
}
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
ヘッダー
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let header = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: opsMainDescriptionSegmentedControlCellId, forIndexPath: indexPath) as! MyHeader
return header
}
ヘッダーの幅をUICollectionView以上で、画面の幅に合わせることは可能でしょうか? – Bigair
あなたの質問が間違っているようです。あなたが現在やっていることは、うまくいくはずです。 UICollectionViewの幅が親ビューの幅と同じに設定されていることを確認してください。 – Tander
ヘッダーの幅がcollectionViewより広い場合、XCodeはエラーメッセージを記録します。アプリケーションはクラッシュしませんが、ヘッダーの幅はコレクションビューの幅にリサイズされます。 – Bigair