Using Non-Retina UIImage for Retina display device - ios

When i started working on my game app i didn't know i should create retina/non-retina #2x, #3x, #1x images. I just created the images with no #1x, #2x, #3x at the end of png file. So since my images are currently called image.png, it's considered a non-retina image i know now. Example is I made an image 25x35 in png. In Storyboards i decided to resize the image and i made it 35x40 because it looks better for iPhone5 than 25x35. My issue is even for 1x i'd have to re-create 40 images from scratch for #3x first and then use Prepo app to automatically downsize to #2x #1x scales. I tested my non-retina images on iPhone 4s/5/5s/6/6+ simulators and iPad 2, Air, Retina simulators and they all look the same and great, and app works well. No blurs or issues. Can I just use my image.png for Retina device as well? Would Apple allow this?

If this is an in-app image, and not the application icon, then yes, you can just use Any resolution image. You can use UIImageView and set contentMode on it to perform AspectFit, ensuring the image will be the same size on every screen type, and also will not get stretched.
myImageView.contentMode = UIViewContentModeScaleAspectFit;
Example: The simplest way to resize an UIImage?
This will preserve the aspect ratio of the image when fitting it to the image view container.
I would provide the image itself with the highest resolution required (#3x), but without #3x in the name, and let UIImageView scale it down to the required size for the other two resolutions.
There is a performance hit in doing this. If it doesn't degrade your scroll performance, go for it.
So basically: start with a high res image and scale down. Do not scale up a low res image, because it won't look crisp. And keep the same aspect ratio so it doesn't stretch.
You will not get rejected for doing this to in-app images.

If all of your assets have the #3x postfix then the App Store recognizes your app as being optimized for the iPhone 6 (together with correctly sized startup images or .xib / .storyboard). Using bigger images for non-retina or normal retina screen causes your RAM usage to increase and slightly taxes your GPU more but for simple apps this isn't a real concern.

Related

Size of image to set as Background image in view controller

I am trying to put a background image on a UIViewController.However i cannot figure out the size needed because the image should support devices from iphone 4s to iPAD...Here are few questions:
1) Should i put those large image on image xcassets on 1x,2x,3x size,if so what should be the size of those images?
2) Or Should i Copy a high resolution image on the bundle itself again if so what should be the size?
We have differnet-2 sizes in assets like here:
(Only for iPhones)
What I found is that, you should opt for first option and 750X1333, 1080X1920 and 1242X2208 should be the 1x,2x and 3x.
You can add more by clicking on tick sign and give sizes like above we give for the iPhones.
Designer will give you proper sizes with respect to resolution to each ipad and iphone
Well it depends on what kind of image you want to display
If it's a solid or pattern image that won't have any different if scaling up / down then I suggest that you put it in image xcassets and use for all supported devices. You should put the largest size image, you can find all screensizes from this: http://iosres.com/
Otherwise, if it's a picture with details like a portrait or food dish, etc. You have to drop it manually with some photo editors like photoshop then add it to xcassets separately for iPhone and iPad
In place of 1x,2x & 3x images take single PDF image and place in image assets it ll fit for all comparability devices.
I think this code will help:
var backGroundImageView :UIImageView! //declare
///set image contentMode in viewDidLoad()
self.backGroundImageView.contentMode = .scaleToFill
However, you should check whether the image is in landscape or portrait orientation.
Image xcassets on #1x,#2x,#3x size will match iPhone 4S screen size automatically, #2x is for the iPhone 5, #3x for the Plus.
As for the iPad you can check the Apple Developers documents.

iOS: Preparing background images for applications

Mostly every iOS application has a view with an image as background. Is there any image sizing guide out there? For example here is an iOS screen designed in Sketch:
As you can see there is a background image. Now there are lots of Apple devices every application should support. The new iOS 10 supports all devices from iPhone 5 to iPhone 6s Plus. They have different screen sizes and resolutions. When creating Xcode assets, I am giving 3 background images with different sizes - #1x, #2x, #3x. What sizes should they be?
The way I see it you have 2 options:
In here you will find the resolutions of the iPhone's:
You don't need the #1 image since you don't support iPhone 4 and 4s (iOS 10).
#2 is for iPhone 5,5c,5S,6 and 6s so basically you can create #2 image of the highest resolution which is the iPhone 6 and this image will work well for the iPhone 5 family.
Or, you can create an image with resolution for each iPhone and using hard coded logic set the image for each phone.
i.e: if iphone5c { setImage("iphone5cImage") } etc etc..
The simplest solution is to create 1 image with the highest resolution. The #3 is the highest for the iPhone 6S+ and it will look amazing for the rest. Don't forget to set the image view as aspect fill.
Also, don't forget to check this thread: How to handle image scale on all the available iPhone resolutions?. It will give you clues of what exactly you are dealing with. TL;DR, It's the options I wrote.
The background images you only need to give are #2x and #3x, because #1x devices are now long gone in the dusty pages of history.
Speaking of #2x and #3x, the image resolutions you give to the developer should be the same with the highest resolution iPhone that uses that given size.
For #2x, that is the iPhone 6, which is 750x1334, and for #3x, the iPhone 6+ which is 1242x2208.
Down-scaling shouldn't be a problem because the aspect ratios of all iPhones that support iOS 10 are the same(16:9).
Note for Developer(s):
The UIImageView will then down-scale the images appropriately,
provided:
1. you created an image set with the provided #2x and #3x images,
2. correctly constrainted the UIImageView to the edges of the superview, and
3. selected the Content Mode of the UIImageView as Scale to Fill or Aspect Fill.
There is design nuance in full size background images. Mostly if the scale aspect fill good enough for different sizes you need to design only for the biggest device size after that the rest of them scale to fit. Sometimes some part of background needs to remain visible or if want to keep a low memory footprint for small device sets you need to create smaller alternatives.
Whenever you make a decision with the design size of asset you need to create #3x,#2x variants.
One more thing I need to point out about vector designs. If your design is made only with vectors you can choose pdf vector export. Storyboards can accept vector assets and they are doing very good when scaling in full backgrounds.
I use background images in my Apps. To solve this problem I use one image that has the resolution to cover all iPhones and all the iPads except the large one.
The image size is 2048x2048 points or 1024x1024 pixels at #2x to cover the 9.7 inch iPad.
The image is compressed JPG to keep the size down. Note that I allow it to scale for iPhone 6 Pluse (#3x) and 12.7 inch iPad Pro (#2x) as the quality doesn't seem to be affected.
I can justify the scaling for the larger devices, because if I provided image for the 12.7 inch iPad Pro, it will be 5464x4096 points (#2x) and 2732x2048 pixels and then the JPG compression would have to be so high (if I wanted to keep the size down), that the quality of the image was low anyway compared with scaling.
If you need high quality try both JPG and PNG for comparison, because the PNG becomes very large for complex images, but gives the best quality.
If you still have the same problem then you can try this one. For this you have to add only one image with good resolution and below code..
UIImage *bgImage = [UIImage imageNamed:#"art_background_star#3x.jpg"];
CGSize screenSize = [UIScreen mainScreen].bounds.size;
UIGraphicsBeginImageContextWithOptions(screenSize, NO, 0.f);
[bgImage drawInRect:CGRectMake(0.f, 0.f, screenSize.width, screenSize.height)];
UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIColor *backgroundColor = [UIColor colorWithPatternImage:resultImage];
self.view.backgroundColor = backgroundColor;
There are 3 kinds of Apple Devices (iPhone and iPad) that is
Normal device which terms to 1 pixel = 1 point#1x (Older iPhone and iPad devices)
Retina device which terms to 4 pixels(2 x 2) = 1 point#2x (iPhone 5+)
Retina iPhone6 and iPad which terms to 9 pixels (3 x 3) = 1 point#3x (iPhone6+)
For iOs 10 that will not support iPhone 4s so you only require #2x and #3x images.
As you can see above attached image iPhone 6 also support #2x Scale so use image size for #2x is of 750*1334 and for #3x is of 1242*2208 with image mode.
Take a look at the page on documentation, there is Static Launch Screen Images, and you can catch sizes from there.
You can get a device screen size, using
CGSize screenSize = [UIScreen mainScreen].bounds.size // (Objective-C)
let screenSize: CGSize = UIScreen.mainScreen().bounds.size // (Swift)
And after you can programmatically select an image you want, from set of an images from the bundle. Or to make a big one image for resizing, using knowledges from documentation, and to resize an image accordingly. Or...your choice.
Different "sizes" #2x, #3x is scale.
And here is the nice explanation.

UIButton and #3x images (using Image Assets)

I've got a problem here and it's easy to explain:
I'm using image assets for a new project being built in Swift 2.0 and Xcode 7.1.
I have a bunch of buttons with images set. The buttons are much larger than the images and so they center (as expected) just fine on any #1x or #2x screens.
However, as soon as I build to the 6+ with its #3x resolution, the button instead uses the dimensions larger than the #1x image and the image in the center of the button becomes larger.
So I have an image that's 20x20, 40x40 (for #2x), and 60x60 (#3x).
If I build to an iPhone 6, the image dimensions are indeed 20x20 and the #2x image is used for the double resolution. But if I build to the 6+, the image dimensions are made larger. I don't know exactly how much larger but it's larger than 20x20. This is only happening with UIButton.
Any help is appreciated.
Turns out it was because I was rendering the images at 4x instead of 3x.

Using less Images for non-retina, retina and retina HD (#1x, #2x, #3x) for Universal Apps

To support iOS 7 to 8 on universal devices, I have to make 4 copies of the same image in different size.
For the iPhones
image#2x.png (iphone 4s,5,5s,6)
image#3x.png (iphone 6+)
For the iPads
image.png (ipad 2, ipad mini 1)
image#2x.png (ipad 3, 4, ipad mini 2, ipad Air)
The images are really bloating the app size.
Is it ok to just use 1 image size, the largest one of the set and scale to fit in the uiimageview and use the image view to scale down the image on the smaller screens?
imageView.contentMode = UIViewContentModeScaleAspectFit;
or is it absolutely necessary to have all 4 copies at different sizes?
It works on all the devices on the simulator and on a retina iPad 3, but I have no way of actual testing on other devices and am afraid that the images may not display.
Has anyone tried using 1 large image instead of the set of copies?
Yes, you can theoretically use the largest resolution image and have the UIImageView scale the image down using mode Aspect Fit.
The only drawback is the older phones that don't support retina also are less performant. For example, when using images on cells of a UITableView and scrolling, the device has to load the large image, then scale the image down, and scroll it at the same time, and it will stutter on old, slower devices.
So, perhaps just use multiple images in list views (should just be thumbnails and are tiny anyway, or just use the smaller images here), but don't worry about larger images that stay on the screen and don't scroll.
Make sure you load images in list views using methods that allow caching like imageNamed:.
As long as you take into consideration the performance penalties involved in scaling down the images, you can use just the largest image and scale it down to fit.
By the way, yes I've used this technique in real live apps in the App Store.
Another technique I've seen is to include lower quality images (1x or 2x) and if you run it on a higher resolution device (2x or 3x), automatically download high resolution images from the web. Maybe be nice about it and only download them on wifi.

How important are non-retina images?

I'm releasing a new update for one of my apps and I was disappointed to see that it just barely surpasses 20MB estimated size (20MB is the point where it can no longer be downloaded over cell data).
My app contains a lot of images, so I could greatly reduce the size if I didn't have all those non-retina images. I know that there are some non-retina devices that will be running my app. So here are my questions:
How will a non-retina device react if I have an image with the #2x suffix but no non-retina image without it.
If I use a retina sized image without the #2x suffix and scale it down to the size I want to display it at programmatically and/or
through interface builder, will it still maintain full quality on
retina devices? Will the quality be worse on a non-retina device
than using an image I downscaled from the original using GIMP
instead?
How will a non-retina device react if I have an image with the #2x suffix but no non-retina i
image without it.
I use that approach on a couple of apps of mine and it works flawlessly. I am not able to detect any performance or visual issues on non-retina display devices (concretely, iPad 1/2 and mini).
I am not sure what can happen on older iOS version, since I only support iOS5+ on those apps.
If I use a retina sized image without the #2x suffix and scale it down to the size I want to display it at programmatically and/or through interface builder, will it still maintain full quality on retina devices? Will the quality be worse on a non-retina device than using an image I downscaled from the original using GIMP instead?
This comes down to how you set interpolation options while doing the scaling. See this other question for more details on how interpolation quality affects scaling down an image. In GIMP or Photoshop you also have control on the interpolation to be used for scaling, btw.
But in the end I don't think you need to go this way.
Most importantly, that bandwidth limit has been raised to 50MB.
OK.
If you only provide one image then you have one of two possibilities.
The image is a non-retina image. This will look fine on the non-retina. It will look identical on a retina device. But will look low quality next to a retina image.
The image is a retina image. On the retina device it will still load as a retina image. It will look fine. However, on the non-retina device it will have to scale down the image. This takes extra cycles of the CPU so could affect performance and it may not look how you want. It may shrink the image using a different method than you want and so may make the image look odd.
This is the same with or without a suffix.
The best solution is to create retina images and then use your editor of choice to create the standard versions. Nothing will stop you only providing one image but it may lead to a look and performance that you don't want.
On a side note. The size for downloading over cellular data was increased to 50MB.
Try these things using the simulator and find out for yourself.
I think the answer is that UIImage will ignore the #2x choice if you're relying on [UIImage imageNamed:#"without2xSuffix.png"] and not find anything, but I haven't tried it. Deliberately requesting the #2x file will work, but whether the image will be scaled, tiled, stretched or centered (or something else) is up to the place where it's used.
Note that the documentation says that unless you use the name without the #2x suffix and let iOS find the 2x version for you, it will set the scale of the image to 1.0 rather than 2.0, which complicates drawing. You'd have to load the image using imageWithData:scale: to fix this.

Resources