Reputation: 3685
I have a UITableViewCell
that has an image view within it:
Which has the following bounds for its large image:
And has the following setting:
The code around this is pretty simple, its using the KingFisher library to fetch the image:
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)
...
}
...
}
However the above code ends up with the image loading in an unclipped manner, seems to complete ignore the bounds? This works else where within my app so I don't think its something wrong with the library and just something I'm missing?
Anyone have any idea why its not clipping?
Upvotes: 1
Views: 232
Reputation: 1529
Common mistake:
UITableViewCell
has its own imageView
property and this is what you are currently setting the image to.
Replace:
cell.imageView?.kf.setImage(with: url)
With:
cell.imgView.kf.setImage(with: url)
Rename your UIImageView
to something like imgView
and update the code, as above, and you should be good.
Upvotes: 2