kishikawakatsumi / IBPCollectionViewCompositionalLayout

Backport of UICollectionViewCompositionalLayout to earlier iOS 12
MIT License
1.55k stars 148 forks source link

Refer collection view size instead of content size in decoration views #57

Closed kishikawakatsumi closed 5 years ago

kishikawakatsumi commented 5 years ago

Refer collection view size instead of content size in decoration views.

let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 5
section.contentInsets = NSDirectionalEdgeInsets(top: 40, leading: 40, bottom: 40, trailing: 40)

let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(
    elementKind: SectionDecorationViewController.sectionBackgroundDecorationElementKind)
sectionBackgroundDecoration.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 5, bottom: 5, trailing: 10)
section.decorationItems = [sectionBackgroundDecoration]

The above code should be rendered as the following;

IBPCollectionViewCompositionalLayout UIKit
Simulator Screen Shot - iPhone Xs - 2019-08-21 at 00 02 57 Simulator Screen Shot - iPhone Xs - 2019-08-21 at 00 02 58

Another example:

let section = NSCollectionLayoutSection(group: group)
section.interGroupSpacing = 5
section.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 0, bottom: 5, trailing: 0)

let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(
    elementKind: SectionDecorationViewController.sectionBackgroundDecorationElementKind)
sectionBackgroundDecoration.contentInsets = NSDirectionalEdgeInsets(top: 10, leading: 5, bottom: 5, trailing: 10)
section.decorationItems = [sectionBackgroundDecoration]
IBPCollectionViewCompositionalLayout UIKit
Simulator Screen Shot - iPhone Xs - 2019-08-21 at 00 07 07 Simulator Screen Shot - iPhone Xs - 2019-08-21 at 00 07 09