Should a universal app have 4 copies of each image? - ios

In a universal app should I have a image.png, image#2x.png, image~ipad.png and image#2x~ipad.png for every image in my project?
Or should I just use my wider iPad images and have iOS scale them down to iPhone for me?
There's a lot of images so I'm a bit concerned about the file size...
Thanks!

Not necessarily but you can see code below. If you are targeting low res iPads and Low res iPhones you would have one set of icons for each. So if you are targeting iPad retina and iPhone retina that is on set of icons too so if you have an image called car.png and car#2x.png you would have 2 icons that cover all 4 models mentioned.
You can of course have images specific for iPad as the screen is larger then in your logic you would show either or depending on the device idiom..like below
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
//Device is iPhone
//This would give you low res icon for iPhone and if device is retina system will show it
UIImage *car = [UIImage imageNamed: #"Car.png"];
UIImageView *carImage = [[UIImageView alloc]initWithImage:car];
}
else {
//Device is iPad
//This would give you low res icon for iPad and if device is retina system will show it
UIImage *carLarge = [UIImage imageNamed: #"CarLarge.png"];
UIImageView *carImage = [[UIImageView alloc]initWithImage:carLarge];
}

Related

UITabbar background image IPhone 6 issue

I'm developing Tab bar Application and found strange issue on iPhone 6
Notice that image is not wide enough for full screen but repeated.
I have set image through both storyboard and programmatically
I have also have 2x and 3x images placed in Images.xcassets
For any one who comes here later, here is what i do
After Some tries i've used a hack as follow
Do not used images from assets instead place them as files (we do before assets)
Check if we have iPhone 6 and user #3x image, (i was not sure why it was not picked by assets but it do in this manner)
Following is code
#define isIPhone6 [[UIScreen mainScreen] bounds].size.height > 568 ? YES : NO
UITabBar *tabBar = tabBarController.tabBar;
UIImage* tabBarBackground = [UIImage imageNamed:#"tab_bar1.png"];
if (isIPhone6) {
tabBarBackground = [UIImage imageNamed:#"tab_bar2#3x.png"];
}
[tabBar setBackgroundImage:tabBarBackground];

How to use xcassets/universal background images for different iPhones/iPads?

I would like to display a different background for each different device (i.e. iPhone 4S, iPhone 5, iPhone6, iPhone 6Plus etc.). I am not talking about launch images but app's backgrounds that will be displayed while using the app.
I have added the following code in my ViewController:
var bgImage = UIImage(named: "main_bg");
var imageView = UIImageView(frame: self.view.bounds);
imageView.image = bgImage
self.view.addSubview(imageView)
self.view.sendSubviewToBack(imageView)
And I am ready to add the assets into the Images.xcassets catalog.
This is what I see when I create a new "Image set"
Therefore, I am trying to match the assets with each different device.
Thanks to this question: universal image support I now know that these devices will access the following images:
iPhone 3 -> 1x (image size: 320x480px)
iPhone 4/4S/6 -> 2x (image size: 640x960px)
iPhone 5/5c/5s/iPod Touch -> Retina 4 2x (image size: 640x1336)
iPhone 6 Plus -> 3x (image size: 1242 x 2208)
My question is, how can iPhones 4/4s and 6 access the same image if, clearly, it's not in the right size for both devices?
Thank you
Try to check this answer:
How to handle image scale on all the available iPhone resolutions?
You can use this code to configure a different image as well:
NSNumber *screenWidth = #([UIScreen mainScreen].bounds.size.width);
NSString *imageName = [NSString stringWithFormat:#"name-%#w", screenWidth];
UIImage *image = [UIImage imageNamed:imageName];

UIImage screen size condition weird behaviour

So I need to differentiate the screen size (3.4 or 4 inch) devices in order to select the right image to display.
Here is what I did: -- from here
#define IS_PHONEPOD5() ([UIScreen mainScreen].bounds.size.height == 568.0f && [UIScreen mainScreen].scale == 2.f && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
if(IS_PHONEPOD5()) {
self.tutorialImageView.image = [UIImage imageNamed:#"tutorialOverlay-568h#2x.png"];
} else {
self.tutorialImageView.image = [UIImage imageNamed:#"tutorialOverlay.png"];
}
Regardless of the screen size the image view always contains the larger image and extends off the screen (on the 3.5")
Am I doing something wrong, I have tried a few other things and it has always done the same thing.
EDIT: Even if I don't ever select the larger image it still is the one on screen at runtime:
self.tutorialImageView.image = [UIImage imageNamed:#"tutorialOverlay.png"];
It is still the larger image?
Have you checked UIViewContentMode of UIImageView? Try it by setting UIViewContentModeScaleAspectFit and check if it works.
don't use #2x in your image string. because every retina device will automatically take care of that.
use should save your image text like image#2x.png but i must use only without #2x extention. use properly like [UIImage imageNamed:#"image.png"]; this is for 3.5 inch.
How to use 4 inch screen use extention with -568h. Eg:
image-568h#2x.png. use like [UIImage imageNamed:#"image-568h.png"];
self.tutorialImageView.image = [UIImage imageNamed:#"tutorialOverlay-568h.png"];
more detail
https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/App-RelatedResources/App-RelatedResources.html
Edited:
self.navigationcontroller.navigationbar.translucent = NO;

Xcode 4.5 background image iPhone 4, 4s, 5

I have in my viewController.m written the background code:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"image.png"]];
And I have the correct names of the different pictures:
image.png for non-retina display (320x480)
image#2x.png for retina display (640x960)
image-568h#2x.png for iPhone 5 (640x1136)
But when I run it in the simulator it does not take the image-568h#2x.png for iPhone 5 screen it only takes the image#2x for 4s screen and scale it to fit the screen... I dont know if there is any coding to use the image-568h#2x for iPhone 5 screen?
Im using Xcode 4.5
iPhone 5 is retina, just like iPhone 4 and 4S, and the #2x-image will be used automatically for all these devices. It's only the startup-image that is called "-568h#2x" for iPhone 5. You need to write some code to use a different image, something like this would work:
NSString *filename = #"image.png";
CGRect screenRect = [[UIScreen mainScreen] bounds];
if (screenRect.size.height == 568.0f)
filename = [filename stringByReplacingOccurrencesOfString:#".png" withString:#"-568h.png"];
imageView.image = [UIImage imageNamed:filename];
if you are trying to use [UIImage imageNamed:#"image.png"] and expect image-568h#2x.png to be picked automatically from the bundle for iPhone 5, it will not work.
Automatic picking works only for iPhone 4 and 4S.
Only the Default image named as Default-568h#2x.png will be picked automatically in iPhone 5.
for normal images, if you have separate image for iPhone 5, try using this code
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
// code for 4-inch screen
} else {
// code for 3.5-inch screen
}
I believe it is incorrect to assume that you can apply the -568h#2x trick to all image files. I think it only works for Default-568h#2x.png. This is the file that iOS looks for at app launch on a 4" display device, as well as the "flag" to enable 4" display support in the SDK. For example, once you include this specific file, your table views will fill the screen.
I have not read anything to suggest that you can simply provide any image with the -568h#2x file name component and have it be used automagically. You'll have to do that yourself based on the screen size, e.g. [UIScreen mainScreen].bounds.size.height.

Orientation problems with launch image in universal app

I have a Universal app with launch screens for iPhone and iPad, following Apple's naming convention for launch screens.
The app is only for Landscape orientation. When I run it on iPhone, the splash screen (which is 320 × 480 pixels) is rotated 90 degrees to the RIGHT, regardless of orientation.
Xcode won't let me rename the launch image to Default-LandscapeLeft.png as it's a Universal app. What can I do to correctly display the launch image?
Maybe you can provide two images, a Default.png for iPhone and Default-LandscapeLeft.png for iPad
Do you have portrait orientations disabled in the project settings?
I ended up fixing this by flipping the UIImageView:
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *iphoneLaunchImage = [UIImage imageNamed:#"Default"];
initialImage = [[UIImageView alloc] initWithImage:iphoneLaunchImage];
//Flip it:
initialImage.transform = CGAffineTransformMakeScale(1, -1);
[self.view addSubview:initialImage];

Resources