Haider Ahmed Haider Ahmed - 4 months ago 14
Swift Question

how can i display 4 images on cells in each row on collectionView

i have question for how can i display 4 images on cells in each row for example (i have collectionView have 10 rows each row have 4 cells for different screens for all devices)on collectionView for each device because i display (4 images for iPhone5 )and (for iPhone 6 is display 5 images )and (iPhone 6 plus it display 6 images )on cells i need to make all these different screens display 4 images on cells in each row in collectionView

thanks Advance

Answer

You can pass your size like this

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let minSpace: CGFloat = 10
    return CGSizeMake((collectionView.frame.size.width - minSpace)/4, YourCellHeight)
}
Comments