【发布时间】:2017-01-03 23:19:30
【问题描述】:
我有一个水平滚动的 UICollectionView,我希望一次在屏幕上显示一个单元格。
我通过以下方法以编程方式设置单元格的宽度和高度:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! Cell
let width = collectionView.bounds.size.width - 40
let height = collectionView.bounds.size.height - 40
cell.bounds.size = CGSize(width: CGFloat(width), height: CGFloat(height))
return cell
}
在努力弄清楚如何使用插入、间距、部分插入(以编程方式和在 XCode 中的检查器中)之后,我似乎无法弄清楚我需要设置什么以及需要在哪里设置它。
【问题讨论】:
标签: ios swift uicollectionview swift3