【发布时间】:2016-10-25 05:12:41
【问题描述】:
我已关注this answer 并尝试每行实现 5 个单元格,当我检查 iPhone 6 和 iPhone SE 时效果很好,如下所示。
但是当我尝试在 iPhone 6 Plus 上运行它时会出现问题。谁能帮我解决这个问题?
这是我的代码。
screenSize = UIScreen.main.bounds
screenWidth = screenSize.width
screenHeight = screenSize.height
let itemWidth : CGFloat = (screenWidth / 5)
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
layout.itemSize = CGSize(width: itemWidth, height: itemWidth)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
layout.sectionInset = UIEdgeInsets(top: 10.0, left: 0, bottom: 10.0, right: 0)
collectionView!.collectionViewLayout = layout
【问题讨论】:
-
看起来那些是图像。他们是吗?储物柜#1000?
-
layout.itemSize = CGSize(width: itemWidth, height: itemWidth) 这是控制您的项目大小。尝试使用 screenWidth/5 作为 itemWidth
-
@MNM 这是一个 UILabel。是的,我尝试输入
layout.itemSize = CGSize(width: screenWidth/5, height: screenWidth/5),但没有运气:( -
尝试将其放入容器视图并将背景涂成黑色
-
你必须在模拟器上运行它。在设备上尝试一下,我认为您不会看到这些线条。
标签: ios iphone uicollectionview swift3 uicollectionviewlayout