I’m making an attempt to make a set view of photos, in order that there are 3 per row, with some spacing in between.
Code:-
func setupCollectioView(){
guard let collectionView = gridPhotosCollectionview, let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout else { return }
flowLayout.minimumInteritemSpacing = 2
flowLayout.minimumLineSpacing = 2
flowLayout.sectionInset = UIEdgeInsets(high: 2, left: 2, backside: 2, proper: 2)
gridPhotosCollectionview.delegate = self
gridPhotosCollectionview.dataSource = self
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection part: Int) -> Int {
return photos.depend
}
func collectionView(_ collectionView: UICollectionView, structure collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let noOfCellsInRow = 3
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left + flowLayout.sectionInset.proper + (flowLayout.minimumInteritemSpacing * CGFloat(noOfCellsInRow - 1))
let measurement = Int((collectionView.bounds.width - totalSpace) / CGFloat(noOfCellsInRow))
return CGSize(width: measurement, top: measurement)
}
func collectionView(_ collectionView: UICollectionView, structure collectionViewLayout: UICollectionViewLayout, insetForSectionAt part: Int) -> UIEdgeInsets {
let totalCount = selectedImages.depend + selectedPostDetailImages.depend
if totalCount == 1 {
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
return UIEdgeInsets(high: 0, left: 0, backside: 0, proper: collectionView.body.width - flowLayout.itemSize.width)
}
return UIEdgeInsets.zero
}
func collectionView(_ collectionView: UICollectionView, structure collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt part: Int) -> CGFloat {
return 10
}
The above code works on all of the gadgets from iPhone 11. it is not working beneath the iPhone 11. Please examine the hooked up screenshots.
iPhone 11 Display Shot:-
iPhone XS Display Shot:-
Query: Easy methods to set the cells body to suit precisely 3 per row in all gadgets, Swift?
Can somebody please clarify to me how to do that, I’ve tried with the above code however don’t have any outcomes but. Please Right me if I am doing improper.
Any assist could be vastly appreciated.