我创建collectionView
并且我有 3 个单元格。我希望我的单元格在所有设备的所有屏幕上看起来都像这样:
但我有 iPad 的这个结果。
如何解决?
更新
我加collectionView
进去UIViewController
。我有这个限制collectionView
:
调整我的细胞大小:
代码:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let itemsPerRow: CGFloat = 3
let itemWidth = (collectionView.bounds.width / itemsPerRow)
let itemHeight = itemWidth * 1.5
return CGSize(width: itemWidth, height: itemHeight)
}