我编写了返回单元格大小的函数UICollectionView
。
fileprivate func getCellSize(with row: Int) -> CGSize {
let percentage: CGFloat = row == 0 ? 0.8 : 0.2
let width = self.collectionView?.frame.width
let height = self.collectionView?.frame.height
let expectedWidth = width! * percentage
let expectedHeight = height! * 0.5
return CGSize(width: expectedWidth, height: expectedHeight)
}
这个功能工作正常,但它有一个小问题,与我的圆角接缝有关。因为我收到的布局没有像预期的那样被单元格完全覆盖。
iPhone 6 模拟器的函数结果如下:
0:行 = (533.60000000000002,187.5)
1:行 = (133.40000000000001,187.5)
实际结果:
预期结果: