Handling different iphone screen sizes/resolution for background images
It all depends on your image:
- If your Image can be stretched, UIImageView will do all the work.
- If only a part of you image should be stretched you should use this:
imageView.image = [imageView.image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right)];
- If your image can't be stretched you should then do different images for the phones and change them in runtime.
UPDATE
For the last point you could do something like this in your viewDidLoad
method:
BOOL isIPhone = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone;
BOOL isIPhone5 = isIPhone && ([[UIScreen mainScreen] bounds].size.height > 480.0);
if (isIPhone5) {
imageView.image = [UIImage imageNamed:@"iphone4image.png"];
} else {
imageView.image = [UIImage imageNamed:@"iphone5image.png"];
}
Handling new iPhone screen sizes with a background image
Image sizes for new iPhone6/6+ are:
For iPhone 6:
750 x 1334 (@2x) for portrait
1334 x 750 (@2x) for landscape
For iPhone 6 Plus:
1242 x 2208 (@3x) for portrait
2208 x 1242 (@3x) for landscape
Hope this will help you.
How to support various iphone screen sizes as of 2014?
If you want to support native resolution of iPhone 6/Plus, you need to add launch images (prior to iOS 8) or launch screen xib (iOS 8).
iPhone 4/4S: 640 x 960
iPhone 5/5S: 640 x 1136
iPhone 6: 750 x 1334
iPhont 6 Plus: 1242 x 2208
That means you need to prepare 4 launch images with above resolution if you want to support these devices. You can use iOS simulator to capture screenshots with different resolutions. Your app will run in compatibility mode
on new resolution devices if it can't find the launch image of the specific resolution. compatibility mode
means your view will be scaled to fit the new screen size when still have the same logical size.
EDIT:
I think op misunderstands what do @2x
and @3x
mean. The resolution of iPhone 6 is 750(pixels) x 1334(pixels), 326 pixels per inch
. This is the REAL resolution. And 375(points) x 667(points)
is the logical size if the native resolution is supported. iPhone 6 Plus's resolution is 1242(pixels) x 2208(pixels), 401 pixels per inch
and the logical size is 414(points) x 736(points)
.
This is how images with different resolutions work on iOS device:
Let's say you want to run your app on iPhone 4s, iPhone 5/5S, iPhone 6/plus. First thing you should do is to provide 4 launch images to support native resolutions of these devices. When iOS launch your app, it will check if the app provides the right launch image to support the native resolution of current device. If iOS finds it, then use that in launch time and the logical size of screen is right, your app runs as normal. Otherwise, your app will run in compatibility mode
in which all of the views will be scaled.
Suppose there is an image named foo.png
in your app of which the logical size is 100(points) x 100(points)
. You want this image looks same in all the above devices. You should provide 2 versions of this image. One is 200(pixels) x 200 (pixels)
and should be named foo.png@2x
and the other is 300(pixels) x 300(pixels)
named foo.png@3x
. If you load this image with [UIImage imageNamed:@"foo"]
, on devices except iPhone 6 plus, the app will load the image named foo.png@2x
. Otherwise the app will load foo.png@3x
and sample it down to 300 * 84%(pixels) x 300 * 84%(pixels).
And if you load an image from an url and need to render it on the runtime. Let's say the size you get is {width:100, height:100}
, the scale is 1.0
. This means the REAL size of this image is 100 * 1.0(pixels) x 100 * 1.0(pixels
. If you don't want it to be scaled, you need to calculate the logical size yourself. You do it like this:
UIImage *image = ... // you get it from an url
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat width = image.size.width / scale;
CGFloat height = image.size.height / scale;
CGRect frame = CGRectMake(50.0f, 50.0f, width, height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.contentMode = UIViewContentModeCenter;
imageView.image = image;
[self.view addSubview:imageView];
Aspect Ratio of Background Image for iPhone X
Rather than use an image as your launch screen, you should try using a launch storyboard.
This could contain a single view controller that contains a UIImageView
, with contentMode = .aspectFill
. This will clip some of the image on either side, but this might be acceptable to you.
Related Topics
Swift Unrecognized Selector Sent to Instance Error
CSS Styled Scrollbars Support for Safari Mobile on iOS 6 Disappeared
Getting Back a Date from a String
How to Batch Request with Afnetworking 2
Xcode 6 with Swift Super Slow Typing and Autocompletion
Ios7 Uiswitch Its Event Valuechanged: Calling Continuously Is This Bug or What..
Is There a Swiftui Equivalent for Viewwilldisappear(_:) or Detect When a View Is About to Be Removed
iOS 7 Uiimagepicker Preview Black Screen
Why Does CSS Background-Size: Cover Not Work in Portrait Mode on iOS
How to Disable the Network in iOS Simulator
iPhone Simulator Suddenly Started Running Very Slow
How to Save Nsmutablearray in Nsuserdefaults
Missing Push Notification Entitlement Warning
"Your Binary Is Not Optimized for iPhone 5" (Itms-90096) When Submitting