Created
November 18, 2019 18:50
-
-
Save anupamchugh/39357cc717d0379c49faccd82dd8faf9 to your computer and use it in GitHub Desktop.
This file contains 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 createLayoutDiffSection() -> UICollectionViewLayout { | |
let layout = UICollectionViewCompositionalLayout { (sectionIndex: Int, | |
layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in | |
var columns = 1 | |
switch sectionIndex{ | |
case 1: | |
columns = 3 | |
case 2: | |
columns = 5 | |
default: | |
columns = 1 | |
} | |
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .fractionalHeight(1.0)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
item.contentInsets = NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2) | |
let groupHeight = columns == 1 ? | |
NSCollectionLayoutDimension.absolute(44) : | |
NSCollectionLayoutDimension.fractionalWidth(0.2) | |
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: groupHeight) | |
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: item, count: columns) | |
let section = NSCollectionLayoutSection(group: group) | |
section.contentInsets = NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20) | |
return section | |
} | |
return layout | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment