UICollectionViewLayout Not working with UIImage in Swift 5 and Xcode 11

后端 未结 2 1728
遥遥无期
遥遥无期 2020-12-20 09:05

Please check this attached code and screen short. It\'s work fine when I set the color of container view but when I add UIImage in cell then it\'s not working. I changed the

相关标签:
2条回答
  • 2020-12-20 09:42

    it is probably because the red is dominating over the image

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
        cell.imgCell.image = items[indexPath.row]
        cell.imgCell.contentMode = .scaleAspectFill
        cell.contentView.backgroundColor = .red
        return cell
    }
    

    try:

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
        cell.contentView.backgroundColor = .red
        cell.imgCell.image = items[indexPath.row]
        cell.imgCell.contentMode = .scaleAspectFill
    
        return cell
    }
    
    0 讨论(0)
  • 2020-12-20 09:47

    Please try this solution. I think there are some changes from Xcode 11. Change the CollectionView Estimate Size to None then it will work.

    0 讨论(0)
提交回复
热议问题