the issue: only on iPhone 11, I have two columns of cells, with very big space in the center, on other devices I have 3 cells on 2 columns, I'd like same result on iPhone 11 too
at this moment my solution is minimumInteritemSpacingForSectionAt from 16 to 5, is there a better solution?
what I am using:
let sectionInsets = UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)
private func configureCollectionView(){
self.collectionView.collectionViewLayout = UICollectionViewFlowLayout()
self.collectionView.register(UINib(nibName: "AmountCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell")
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
extension SavingsSettingViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.viewModel.amountItems.value.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! AmountCollectionViewCell
cell.title = self.viewModel.amountItems.value[indexPath.row].description
return cell
}
}
extension MyController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 16
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 16
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemsPerRow = CGFloat(3.0)
let paddingSpace = sectionInsets.left * (itemsPerRow + 1)
let availableWidth = view.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow
return CGSize(width: widthPerItem, height: 59)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return self.sectionInsets
}
}