Fill UIImageView Aspect - Image Outside UIImageView

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

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

In any case, I'm currently trying to use AspectFill mode (I already tried AspectFit and ScaleToFill, and this is not what I'm looking for) for my UIImageView in a UITableViewCell, but for some reason my image is taller than the cell height:

enter image description here

I do not understand what I am doing wrong. This is not an automatic layout, it is a fixed height. Why didn't he work?

+5
source share
2 answers

Make sure the clipsToBounds UIImageView property is YES (or true in Swift).

+18
source

It looks like your image image is the right size, but UIImageView does not automatically crop the image. You need to set the UXmageView clipToBounds property to YES, you can do this in code:

 [imageView setClipsToBounds:YES]; 

Or using the interface constructor:

enter image description here

+5
source

All Articles