图像溢出边界与剪辑到边界集

问题描述 投票:1回答:1

我有一个UITableViewCell,里面有一个图像视图:

enter image description here

其大图像具有以下范围:

enter image description here

并具有以下设置:

enter image description here

围绕这个的代码非常简单,它使用KingFisher library来获取图像:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let element = comments[indexPath.row]
        ...
        tableView.register(UINib(nibName: "CommentImagePostCell", bundle: nil), forCellReuseIdentifier: "CommentImagePostCell")


        if (element.Image != "" ){
            let cell = tableView.dequeueReusableCell(withIdentifier: "CommentImagePostCell", for: indexPath) as! CommentImagePostCell

            let urlString = API.baseUploadURL + element.Image
            let url = URL(string: urlString)
            cell.imageView!.kf.setImage(with: url)

      ...
     }
     ...
}

但是上面的代码最终以未剪切的方式加载图像,似乎完全忽略了边界?这在我的应用程序中的其他位置,所以我不认为它的库有什么问题,只是我缺少的东西?

任何人都知道为什么它不剪裁?

enter image description here

swift uiimageview
1个回答
1
投票

常见的错误:

UITableViewCell有自己的imageView属性,这就是你正在设置的图像。

更换:

cell.imageView?.kf.setImage(with: url)

附:

cell.imgView.kf.setImage(with: url)

将你的UIImageView重命名为imgView并更新代码,如上所述,你应该很好。

© www.soinside.com 2019 - 2024. All rights reserved.