I'm using SDWebImage to download images async into UICollectionView cells, but the downloaded images didn't fit the cell, where the cell only shows the upper corner of the image.
this is my code :
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! ImageCell
cell.imageView.setShowActivityIndicator(true)
cell.imageView.setIndicatorStyle(.gray)
cell.imageView.sd_setImage(with: URL(string: imageURL[indexPath.row]))
return cell
}
and this's my cellClass :
private class ImageCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
self.setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let imageView: UIImageView = {
let imageView = UIImageView()
imageView.backgroundColor = .white
imageView.layer.masksToBounds = true
return imageView
}()
func setupViews() {
backgroundColor = .white
addSubview(imageView)
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.frame = CGRect(x: 0, y: 0, width: frame.width , height: frame.width )
}
}
I had followed this link Resize UICollectionView cells after image inside has been downloaded to solve it, but nothing changes.
So any ideas ?