Ios 如何使用SDWebImage调整加载图像的大小?

Ios 如何使用SDWebImage调整加载图像的大小?,ios,swift3,uicollectionview,uicollectionviewcell,sdwebimage,Ios,Swift3,Uicollectionview,Uicollectionviewcell,Sdwebimage,我正在使用将图像异步下载到UICollectionView单元格中,但下载的图像与单元格不匹配,单元格仅显示图像的上角 这是我的代码: override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(w

我正在使用将图像异步下载到UICollectionView单元格中,但下载的图像与单元格不匹配,单元格仅显示图像的上角

这是我的代码:

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
}
这是我的手机课:

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 )

}
}
我按照这个链接来解决它,但没有任何变化


有什么想法吗

如果不想使用自动约束,则应删除此行

imageView.translatesAutoresizingMaskIntoConstraints = false

当您以编程方式使用自动约束时,您应该使用此选项。

jazak allah kheer,(谢谢兄弟),请您进一步解释。看看这些链接,我认为足以抓住要点,我很感激。您好@Mohammad接受的答案对您有效吗?@nikdange_我绝对有效。