Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacMan988

macrumors 6502a
Original poster
Jul 7, 2012
889
165
Hi,

I need to programatically check for the screen size and if it is iPhone 6 then the app should load the background image with the correct size.

I used the bellow code to check the screen size.

Code:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

This returns 667 x 375.

But when I set the UIImageView's frame to 0, 0, 667, 375 it doesn't fit the screen (my app runs in the landscape orientation only). I figured it out that the 1080 x 768 size makes the UIImageView fitting the entire screen. I'm confused as this is neither the resolution read in points or the native resolution of the device?
 
Sounds odd. it should work.

But this is not the way Apple is advicing you deal with various size screens, check out auto layout.

----------

Can you post the code the image and a screen shot of the result?
 
I would write a helper class to detect the _device_ and use that to fetch images with a device specific prefix/suffix, then just build out your assets to the proper specification.
 
Hi,

I need to programatically check for the screen size and if it is iPhone 6 then the app should load the background image with the correct size.

I used the bellow code to check the screen size.

Code:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

This returns 667 x 375.

But when I set the UIImageView's frame to 0, 0, 667, 375 it doesn't fit the screen (my app runs in the landscape orientation only). I figured it out that the 1080 x 768 size makes the UIImageView fitting the entire screen. I'm confused as this is neither the resolution read in points or the native resolution of the device?

Along with D.T.'s advice, you should really remember that UIImageView is actually returning the points available to draw your image.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.