UICollectionView
然而,我试图通过使用
view.frame.width
细胞的宽度,但不幸的是我好像做错了什么。
UIViewController
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
let cellWidth : CGFloat = 110.0
//let screenWidth = screenSize.width
let numberOfCells = floor(self.view.frame.size.width / cellWidth)
let edgeInsets = (self.view.frame.size.width - (numberOfCells * cellWidth)) / (numberOfCells + 1)
return UIEdgeInsetsMake(20, edgeInsets, 0, edgeInsets)
}
故事板
如何使UICollectionView正确地以均匀的左右间距并排显示两个单元格?