【发布时间】:2019-10-16 00:02:35
【问题描述】:
我正在根据其中的字符串设置集合视图单元格大小。我第一次使用这段代码,结果还可以,第二次或更多次重新加载集合视图时会发生这种情况(请看图片)
这是我的代码:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
var i:Int = 0
var size = CGSize()
for t in mainCategoryDic {
if(i == indexPath.row) {
let index:String = t.key
size = (mainCategoryDic[index]?.name?.size(withAttributes: [NSAttributedString.Key.font : UIFont(name:font_name, size: 14)!]))!
}
i += 1
}
return CGSize(width: size.width + 38.0, height: 30.0)
}
【问题讨论】:
标签: swift layout collectionview reloaddata