max_
max_

Reputation: 24481

Retain the size of a cell.imageView irrespective of the image size

I have a UITableViewCell which contains a UIImageView that resizes itself depending on the size of its image. Please could you tell me how I could retain the size of the UIImageView irrespective of the size of the image.

Upvotes: 0

Views: 1297

Answers (1)

mvds
mvds

Reputation: 47034

Generally speaking, a UIImageView doesn't resize in response to the size of the image. What does happen, is that the UIImageView will not clip the contents, so that you see the image exceeding the UIImageView bounding frame.

You could make the UIImageView resize the image to fit into the box, by doing

imageview.contentMode = UIViewContentModeScaleAspectFit;

or to fill the box:

imageview.contentMode = UIViewContentModeScaleAspectFill;

or you could let it crop the image:

imageview.clipsToBounds = YES;

Upvotes: 5

Related Questions