8
votes

I have a UITableView with cells that contain images. I want to download a big image from the server and insert it into my cell.

My UITableViewCell has a fixed height and fills the entire width of the screen. The best solution will be to resize the image proportionally to fit the screen width and then crop the area with the fixed height, but I found that resizing a UIImage is really hard, and I don't understand why. If you can help me with this, it will be very good.

Anyway, at the moment, I am trying to use the AspectFill mode (I already tried AspectFit and ScaleToFill and it is not what I am looking for) for my UIImageView in UITableViewCell, but for some reason, my image is higher than the cell height:

enter image description here

I don't understand what I am doing wrong. It is not auto layout, it is fixed height. Why didn't it work?

2

2 Answers

26
votes

Make sure to set the clipsToBounds property of the UIImageView to YES (or true in Swift).

6
votes

It looks like your image view is the right size, but UIImageView does not automatically clip an image. You need to set your UIImageView's clipsToBounds property to YES, you can do this in code:

[imageView setClipsToBounds:YES];

Or using interface builder:

enter image description here