Reputation: 4646
I am trying to select an image from photo library, this is the photo which I have downloaded from net and is stored in my photo lib.
So now I want to give user an option to select an image from photo lib and apply as a backgroundImage throught my app, but when I do it, I get the image this way on my iphone screen
Actually the image has been filled the screen, because the content mode specified is "scaleToFill".
1) I want to know how to make this image maintain its aspect ratio and also fill the screen?
Regards Ranjit
Upvotes: 1
Views: 1562
Reputation: 649
check this blog. use these two files
UIImage *image = [UIImage imageNamed:@"SomeImage-900x675"]; // SomeImage-900x675.png
CGFloat targetWidth = 320.0;
CGFloat scaleFactor = targetWidth / image.size.width;
CGFloat targetHeight = image.size.height * scaleFactor;
CGSize targetSize = CGSizeMake(targetWidth, targetHeight);
UIImage *scaledImage = [image resizedImage:targetSize interpolationQuality:kCGInterpolationHigh];
Upvotes: 2
Reputation: 304
though your image is taking all the screen size, Your image size is biger...You will try by scaling image with following resolutions 320*480, 640*960, 1240*2208
Upvotes: 0