Explicitly add #2x to non retina devices - ios

We have a mystery !
In our app we use only retina images (#2x marked).
Until yesterday non-retina devices showed the images well even when we called the images without #2x at the end.
For example if the file name is 'fun#2x.png' we called [UIImage imageWithName:#"fun"].
Today it stopped working and now we have to call [UIImage imageWithName:#"fun#2x"] for the image to display. (The device is iPhone 3GS iOS 5.1).
We are now afraid that we don't understand something about the retina naming.
What changed ?
What is the correct way to deal with it?
Thanks
Shani

You should provide non-retina images! The downscaling isn't a good option. The problem here is that iOS tries to find the fun.png image and doesn't find it. Therefore can't present something.
I have no explanation why it worked before. Are you sure?

In apps I have worked on if I am only supplying 1 image (the 2x one) than I just use the full image name, ie:
[UIImage imageWithName:#"my-image.png"]
When I am supplying images for certain buttons that I need have 2 versions of, I use:
[UIImage imageWithName:#"my-image"]
Doing it this second way, you must supply a retina & non-retina image with that base name
Like dasdom said it should have not been working before that way-- and even if it somehow was you should stick to what I said above if you want your images to always display.

Related

Do I need to include images for a non-retina iPhone and 6+?

In my app I am using images of size 155*155pts so I am supplying it with an image of 310*310px resolution. I know that I can use image.png image#2x.png and image#3x.png and then [UIImage imageNamed: image] to select the image appropriate for the resolution. My question is do I really need to include a lower resolution version of size 155*155px, won't the UIImageView it's displayed in just scale it appropriately? A similar question for the iphone6+, if I don't include the #3x version will it just use the #2x and display it as clearly as a standard retina screen would?
Even though there are plenty of answers at SO discussing this topic
(Google them) e.g. How to handle image scale on all the available iPhone resolutions?
Its just a recommendation to to use scaled up images with #2x and #3x in your app. You don't have to create them. From my experience in making apps, in almost all of them I have never used multiple images. I create one UIImage and use it for all the phone sizes. I then either use auto layout or manually adjust the width height of UIImages myself.
There is a reason I do that is lets say one of your sample1.png image is 1MB then you will need to create 3 of them.
sample1.png
sample1#2x.png
sample1#3x.png
You just doubled or tripled your binary size which is bad for downloads. There always be users running non-retina devices and it would be shame to not support them. Can you only make retina enabled apps, of course you can and Apple will approve those as they will be testing your apps on the latest devices but the best approach is to support all devices.
It depends, if you only support non-retina devices you donĀ“t have to add the normal image size anymore.
The scaling for the 6+ works with the #2x images but i guess you will see a quality difference

iOS, support retina display

When supporting retina, and non-retina displays you would provide the image.png & image#X2.png with relating resolutions.
I understand that iOS will decide which image to use based on the user's device. However, I'm using the images via code, not storyboard.
self.imagePortrait = [UIImage imageNamed:#"image.png"];
Even though I have not specified image#X2.png, will iOS make use of it?
In this case yes. UIImage's -imageNamed: is smart enough to choose the correct resource. (And note that the suffix is #2x, not #X2.)
From the docs:
If the screen has a scale of 2.0, this method first searches for an
image file with the same filename with an #2x suffix appended to it.
Other methods (like -initWithContentsOfFile:) do not have these smarts built in.

Can we use just one set of image assert for all resolutions in iOS Development

I just want to use one set of image asserts for all iPhones and iPads(Universal), Is it possible to do the same? or what will be the best solution for the making a build lighter.
YES, it is possible ti use one image asserts for all devices. just add new image set
in assert by Right click. And the add images for required devices in created Image set.
you can use Image set but it's name,and images are automatically loaded with different devices.
UPDATED
if you want to titlelogo.png for all device then make new image set in Images.xcassets and name it as AssetTitlelogo. and the add all images in it as in screenshot.
You use image by
[UIImage imageNamed:#"AssetTitlelogo"]; /// use your asset Name
It's load right image for right Device..
Yes, if you use a retina image without the #2x or #3x in the name and your UIImageView is set to ScaleToFill it will automatically scale down your image on non-retina devices. it is easy to test with the simulators to see how the image will look at the different screen resolutions.
the trade off is non retina devices will suffer with more memory usage than is needed for them (and usually the non-retina devices are some what limited in memory already compared to the latest apple products) but if you arent dealing with a lot of images on the screen at once then this shouldnt have an adverse effect

load image by "imagenamed" method in xcode 6

I feel this should be a typical question, but haven't found any answer yet. Basically what I'm trying to do is load image by imagenamed method for iPhone, iPad, Retina and non-Retina. What I'm doing is
Add 4 images into image assets. (image_name~iphone.png, image_name#2x~iphone.png, image_name~ipad.png and image_name#2x~ipad.png) and set the image set name to "image_name".
In the code I just call [UIImage imageNamed:#"image_name"] to load for different devices and resolutions.
The problem is the edges of the image look distorted for non-Retina devices like iPad mini and iPad 2. I'm thinking maybe it is not picking the right image for the non-Retina devices. Is there anything wrong with my naming conventions? Any suggestions are welcome!
sorry for the interruption. It ends up to be a problem of the image.=P

iOS #2x applied to non-retina and not scaling correctly

I have *#2x version of every image I use in my app and as long as I test in simulator everything works fine. But for some reason on my iPod 4 (non-retina) app not only loads wrong images, but also scales them about 4 times their accual size. Answer given in this topic would help with scaling problem, but I still have to solve non-retina - retina issue.
you need to have two files one for retina and other for non-retina display
ex:
myImage#2x.png (bigger file for retina)
myImage.png (smaller file for non-retina)
and then just call [UIImage imageNamed:#"myImage"]
it should work
*make sure to clean everything, and try again.. hope that helps.
you have to make background.png (320-480) for non-retina. and background#2x.png (640-960) for retina, if you want to develope for iphone5 too you have to make a background-568h#2x.png (640-1136) too

Resources