![](/img/trans.png)
[英]Call a UICollectionView Cell in sizeForItemAtIndexPath
[英]Swift : UICollectionView Cell can not update frame when implement sizeForItemAtIndexPath
当我实现以下代码时:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
let cellW = (ScreenWidth - 10 - 10 - 30) / 4
return CGSize(width: cellW, height: cellW * 1.5 )
}
通过使用 sizeForItemAt 方法,我可以绘制我想要的框架,但是我的自定义 collectionview 单元格无法更新,我错过了哪里,请帮助我!
我通过这个引用修复它UICollectionView 单元格子视图不调整大小
谢谢你们,首先我的 Cell.imageview 仍然有问题,不能像我想要的那样圆形,我为 imageview 创建了一个类,如下:
class CellImageView: UIImageView {
override func layoutSubviews() {
super.layoutSubviews()
let radius: CGFloat = self.bounds.size.width / 2.0
self.layer.cornerRadius = radius
self.clipsToBounds = true
}
任何东西都可以完美运行
对我来说,在iOS的13,我已经第一固定estimatedItemSize
到.zero
并设置itemSize
等;
if let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
layout.estimatedItemSize = .zero
layout.itemSize = CGSize(width: collectionView.frame.size.width, height: 80)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.