Last active
July 10, 2019 23:48
-
-
Save yfujiki/0547d95fe81fc2feae96a064f137fd74 to your computer and use it in GitHub Desktop.
Brand Names Section for https://github.com/yfujiki/CompositionalLayoutSample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupBrandNamesSection() -> NSCollectionLayoutSection { | |
// 1. Creating section layout. Item -> Group -> Section | |
// Item | |
let item = NSCollectionLayoutItem( | |
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .fractionalHeight(1.0))) | |
item.contentInsets = NSDirectionalEdgeInsets(top: 0.0, | |
leading: 8.0, | |
bottom: 0.0, | |
trailing: 8.0) | |
// Group | |
let group = NSCollectionLayoutGroup.vertical( | |
layoutSize: NSCollectionLayoutSize(widthDimension: .estimated(136), | |
heightDimension: .absolute(44)), | |
subitem: item, | |
count: 1) | |
// Section | |
let section = NSCollectionLayoutSection(group: group) | |
section.contentInsets = NSDirectionalEdgeInsets(top: 16.0, | |
leading: 0.0, | |
bottom: 16.0, | |
trailing: 0.0) | |
// 2. Magic: Horizontal Scroll. | |
section.orthogonalScrollingBehavior = .continuousGroupLeadingBoundary | |
// 3. Creating header layout | |
section.boundarySupplementaryItems = [headerViewSupplementaryItem] | |
return section | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lazy var headerViewSupplementaryItem: NSCollectionLayoutBoundarySupplementaryItem = { | |
let headerViewItem = NSCollectionLayoutBoundarySupplementaryItem( | |
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .absolute(44)), | |
elementKind: UICollectionView.elementKindSectionHeader, | |
alignment: .top) | |
headerViewItem.pinToVisibleBounds = true | |
return headerViewItem | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment