So basically I have a collection view layout that looks like this:
which is a 3 per row image that is super close to each other like instagram. The problem here is that when I go to an ipad or a smaller phone like iphone se the layout gets distorted. This is what it looks like on an ipad
The collection view layout code is this:
func callCustomFlowLayout(collectionView: UICollectionView) {
let flow = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
let itemSpacing: CGFloat = 1
let itemsInOneLine: CGFloat = 3
flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
let width = UIScreen.main.bounds.size.width - itemSpacing * CGFloat(itemsInOneLine - 1) //collectionView.frame.width is the same as UIScreen.main.bounds.size.width here.
flow.itemSize = CGSize(width: floor(width/itemsInOneLine), height: width/itemsInOneLine)
flow.minimumInteritemSpacing = 1
flow.minimumLineSpacing = 1
}
Thanks for any future help. I just want it to be 3 images per rows and adjusting the image size based on the size of the device.
Here is my layout code
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cellsAcross: CGFloat = 3
let spaceBetweenCells: CGFloat = 1
let dim = (collectionView.bounds.width - (cellsAcross - 1) * spaceBetweenCells) / cellsAcross
return CGSize(width: dim, height: dim)
}