本文介绍了如何在所有设备中使用swift4在CollectionView中显示两列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要在collectionView中仅显示两列,我正在使用这段代码
To show only two columns in a collectionView i am using this piece of code
let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
layout.minimumInteritemSpacing = 4
layout.itemSize = CGSize(width:(self.collectionView.frame.size.width - 10)/2,height: (self.collectionView.frame.size.height)/3)
,但只能在5s上正确显示,而不是在每台iphone上都能正确显示.请帮忙.
but it is only showing properly on 5s, not on every iphone. please help.
我想给我的视图控制器显示这样的图像.请帮助任何人
i want to show my view controller like this image. please help anyone
推荐答案
将此代码添加到 viewDidLoad .根据您的身高来改变身高.
add this code to viewDidLoad.change height according to you.
尝试一下!
if let layout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout{
layout.minimumLineSpacing = 10
layout.minimumInteritemSpacing = 10
layout.sectionInset = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
let size = CGSize(width:(collectionView!.bounds.width-30)/2, height: 250)
layout.itemSize = size
}
这篇关于如何在所有设备中使用swift4在CollectionView中显示两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!