I am using the UICollectionViewCompositionalLayout to layout my cells in a collectionView. I want the width of the items in a row to auto adjust so as to fill the collectionView's width. However this is not happening even after setting the fractionalWidth to 1.0 on groupSize. Here is the code:
override func viewDidLoad() {
super.viewDidLoad()
collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout())
collectionView.backgroundColor = UIColor(red: 157.0/255.0, green: 159.0/255.0, blue: 162.0/255.0, alpha: 0.5)
collectionView.register(CollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.dataSource = dataSource
}
private func createCollectionViewLayout() -> UICollectionViewLayout {
// Define Item Size
let itemSize = NSCollectionLayoutSize(widthDimension: .estimated(100.0), heightDimension: .absolute(52.0))
// Create Item
let item = NSCollectionLayoutItem(layoutSize: itemSize)
// Define Group Size
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .absolute(52.0))
// Create Group
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [ item ])
group.interItemSpacing = .fixed(1.0)
// Create Section
let section = NSCollectionLayoutSection(group: group)
return UICollectionViewCompositionalLayout(section: section)
}