【发布时间】:2019-06-16 05:53:28
【问题描述】:
我知道一些与此相关的问题,但我之前尝试过这些问题,但仍然没有运气。
这是我在以下屏幕截图中的问题 我当前的屏幕显示一个固定的单元格大小,它显示较小的内容和较大的内容用点覆盖单元格的空白空间..
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.catCollectionView{
let catCell = collectionView.dequeueReusableCell(withReuseIdentifier: "catCell", for: indexPath)
as! catCell
DispatchQueue.main.async {
catCell.configureCell()
let catCountInt = self.catCountArray[indexPath.row]
catCell.catCountLabel.text = String(catCountInt)
catCell.catNameLabel.text = self.categoryNameArray[indexPath.row]
catCell.catCountLabel.sizeToFit()
catCell.catNameLabel.sizeToFit()
}
return catCell
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let catCell = collectionView.dequeueReusableCell(withReuseIdentifier: "catCell", for: indexPath)
as! catCell
catCell.catNameLabel.text = self.categoryNameArray[indexPath.item]
catCell.catNameLabel.sizeToFit()
let labelWidth = catCell.catNameLabel.frame.width + 10
print("frame width: \(labelWidth)")
return CGSize(width: labelWidth, height: 21)
}
}
也许我在这里遗漏了一件简单的事情,但我现在无法弄清楚。请帮助我,并为我奇怪的英语感到抱歉。
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell uicollectionviewlayout