some_id
some_id

Reputation: 29896

Displaying a UIImageViews image to the size of the actual image

How does one set a UIImageview's image to the actual image size rather than filling the view with the image and thus stretching the image(if the image is smaller than the UIImageView's size)

Upvotes: 0

Views: 1496

Answers (3)

Rhubarb
Rhubarb

Reputation: 35863

Note that if you're in IB or a Storyboard, click on the Attributes inspector tab after selecting your imageview, look down in the View section (under ImageView) and where it says "mode", change the selection from "scale to fill" (the default) to "center"

I think this is basically the IB equivalent of Tommy's answer, which does the same only programmatically.

Upvotes: 0

Anand
Anand

Reputation: 1983

Create the UIImageView like this:

UIImageView *aImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImage.png"]];

So the ImageView has the size of the image.

I hope my answer helps you.

Upvotes: 1

Tommy
Tommy

Reputation: 100652

You want to adjust the contentMode property. I suspect to UIViewContentModeCenter.

Upvotes: 2

Related Questions