我有一个UITableViewCell
,里面有一个图像视图:
其大图像具有以下范围:
并具有以下设置:
围绕这个的代码非常简单,它使用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)
...
}
...
}
但是上面的代码最终以未剪切的方式加载图像,似乎完全忽略了边界?这在我的应用程序中的其他位置,所以我不认为它的库有什么问题,只是我缺少的东西?
任何人都知道为什么它不剪裁?
常见的错误:
UITableViewCell
有自己的imageView
属性,这就是你正在设置的图像。
更换:
cell.imageView?.kf.setImage(with: url)
附:
cell.imgView.kf.setImage(with: url)
将你的UIImageView
重命名为imgView
并更新代码,如上所述,你应该很好。