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.
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.
An object that manages image data in your app.
width)) > (targetSize. height / image. size. height))) //scale to fit width, or scaleFactor = targetSize.
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];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With