强制collectionView只有2行 [英] Enforce collectionView to have only 2 rows

查看:133
本文介绍了强制collectionView只有2行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须制作一个集合视图,这样无论iphone大小如何,我们每行只有2个图像,并且我们还需要每个行和列之间的边框,如图所示。

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 image.

我想这样:

推荐答案

试用此代码:只是,一个不同的方法..

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.

这篇关于强制collectionView只有2行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆