How to resize UICollectionViewCell in iPhone 6 and 6 Plus using autolayout

戏子无情 提交于 2019-12-04 10:14:03

Math trick recall square root Number 33 = items count! You can tweak it independently from your total items count for sizing and feet more or less items in screen!!! For example / (Double(33)) on iPhone 4 will feet 33 items in 4 columns and 4 items per row! in iPhone 6 Pluse you will see same picture cells will scale up respecting 4 columns! If you put 1 you will get one cell full width on whatever 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)

        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!