Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stretch the image size in iphone UIImage or UIImageView

I'd like to show an image in an iPhone app, but the image I'm using is too big. I'd like to scale it to fit the iPhone screen, I can't find any class to handle it.

like image 974
BlueDolphin Avatar asked Oct 29 '08 00:10

BlueDolphin


People also ask

How do I change aspect ratio in UIImageView?

If you are resizing UIImageView manually, set the content mode to UIViewContentModeScaleAspectFill . If you want to keep content mode UIViewContentModeScaleAspectFit do not resize imageview to 313. Image will adjust maximum possible width and height , keeping it's aspect ratio.

What is uiImage?

An object that manages image data in your app.

How do I resize an image in Objective C?

width)) > (targetSize. height / image. size. height))) //scale to fit width, or scaleFactor = targetSize.


2 Answers

UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"your_image.png"]];
view.frame = CGRectMake(0, 0, width, height);

To get the frame of the iPhone screen you can use

CGRect frame = [[UIScreen mainScreen] bounds];
like image 84
Max Stewart Avatar answered Oct 11 '22 23:10

Max Stewart


In Interface Builder, select your UIImageView. From the Tools menu, select "Attribute Inspector". In the Image View Attributes palette, select "Scale to Fill" from the Mode popup. That should scale your image to fit.

like image 35
Ben Gottlieb Avatar answered Oct 11 '22 23:10

Ben Gottlieb