A mathematical trick calls the square root Number 33 = number of objects! You can configure it regardless of the total number of items for calibration and the legs of more or less items on the screen !!! For example, / (Double (33)) on iPhone 4 will process 33 items in 4 columns and 4 items in a row! in iPhone 6 Plus you will see that the same cameras will scale, observing 4 columns! If you put 1, you will get one full-width cell on any device screen!
// ...........returning cell size based on device screen size by calculating square roo func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { let deviceSize = UIScreen.mainScreen().bounds.size let flexSize = sqrt(Double(deviceSize.width * deviceSize.height) / (Double(33))) return CGSize(width: flexSize , height: flexSize) }
source share