I have to make one collection view so that irrespective of iphone size we have just 2 images in each row and also we need border between each row and column as shown in the
Try this code. Just a different approach.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.sectionInset = UIEdgeInsets(top: 6, left: 4, bottom: 6, right: 4)
layout.minimumInteritemSpacing = 04
layout.minimumLineSpacing = 04
layout.invalidateLayout()
return CGSize(width: ((self.view.frame.width/2) - 6), height: ((self.view.frame.width / 2) - 6))
}
Output from above code on different devices.