let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),
heightDimension: .fractionalHeight(1))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1),
heightDimension: .absolute(44))
let group = NSCollectionLayoutGroup(horizontal: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
let layout = UICollectionViewCompositionalLayout(section: section)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
...
复制代码
如今,你已经掌握了打造精彩UI的秘诀!无论是在旧版还是新版iOS系统上,都可以享受到UICollectionViewCompositionalLayout带来的便利。赶快尝试一下吧!
IBPCollectionViewCompositionalLayoutBackport of UICollectionViewCompositionalLayout to earlier iOS 12项目地址:https://gitcode.com/gh_mirrors/ib/IBPCollectionViewCompositionalLayout