像这样的代码
collectionLayout.estimatedItemSize = CGSize(width: 50, height: 25)
collectionLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize
collectionLayout.minimumInteritemSpacing = 10
for _ in 0 ..< 1000 {
let length = Int(arc4random() % 8)
let string = randomKeyByBitLength(length)
array.append(string!)
}
collectionView.reloadData()
Run Code Online (Sandbox Code Playgroud)
细胞限制:
当我在iOS 12上运行它时,它是不同的.左模拟器是iOS 11,右边是iOS 12:
但是,当我滚动它时,细胞的帧将是正常的.