iOS: Preparing background images for applications - ios

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.

Related

Understanding Image Size for Different Resolution Screens

I'm having a hard time putting all the information on image sizes for #1x, #2x, and #3x together. I've been using the scene editor in XCode with the scene size being 1334x750 (pixel dimensions of the screen of the iPhone 6). So when I size an image for a sprite in that scene, is that the size I should use for the #2x?
From what I've read in the documentation CGSize uses points, not pixels, so if I have an image that is CGSize(width: 50, height: 50), is this independent of my scene size in the scene editor?
Bottom line question: How does the CGSize dimensions translate to how I export my images for #1x, #2x, and #3x in pixels and what should the PPI be when I export?
Xcode can handle vector images, so you can forget about #2X and #3X images if you are able to export your images as PDF e.g. in Sketches export panel one of the options for export format is PDF, so create your artwork #1X and export as PDF, then in Xcode when you add the image to Assets.xcassets, you can set the images Scales attribute to Single Scale. Xcode will generate the required #2X and #3X images from your vector PDF at build time.
The concept is simple. The size in Storyboard or Interface Builder should be the size of you asset in #1x format.
The retina display ( or the iPhone 6+ #3x size ) does not mean than you have much space than before, it means that you can draw 2 ( or 3 ) pixels where you draw 1 before.
So for a 50x50 px Image View, cou should have 3 assets :
- Image#1x.png ( 50x50 px)
- Image#2x.png ( 100x100 px)
- Image#3x.png ( 150x150 px)
Suppose you have created an image in your assets library consisting of 3 sets of same image, #1x.png having size 50x50 pixels, #2x.png of size 100x100 pixels and #3x.png size 150x150 pixels.
you don't needs to worry about which one to use in your storyboard(because storyboard automatically using #1x.png), and which one to use for the targeted device like as iPhone6, or iphone7, or iPad(because by default programing all hardware finds out their pixels relative required image among those #1x.png, #2x.png and #3x.png)
for further instructions you needs to study Auto layout Programing Guide
you can also view their apple's tutorial videos regarding Auto layout.
mysteries of auto layout part1
mysteries of auto layout part2
#1x and #2x used to relate to the retina graphics change when iPhone 4 came out.
iPhone 3GS was 320x480, iPhone 4 was 640x960. This meant that the points per inch were literally the same, but the ppi was doubled, hence the #2x. When the iPhone 5 came out, the only thing that changed was the height, so the ppi was the same for the width, no problems here.
Then we hit the 6 and 6+. At this point, apple said screw it, try to keep ppi that correlate to previous iPhones without having keep the previous iphones usable area, or provide bigger screen pixels for bigger devices. Now #2x has lost its original meaning
But, to really throw us off, they made the iPhone SE, which went back to the ppi screen size of the iPhone 5, so #2x makes sense again.
Basically, when thinking of the #2x graphics, think about the 1st iPhone resolution size.
Now, you have a choice to make. You can give your apps more/less usable area, you can black box the extra usable area, or you can scale and take some kind of quality loss due to game pixels not being 1:1 with the screen pixels anymore.

Iphone6 and Iphone 6Plus Resolution #x2/#x3

I've a question about resolution of Iphone 6 and Iphone 6 Plus.
I would like to know something about #x2 and #x3, i really need to be sure !
If i've a fullscreen UIImageView, display on a Iphone 6(667x375 points) the size of the containing UIImage have to be 1334x750 because the size in points are 667(#x2)x375(#x2), right?
So if i understand, the UIImageView on Iphone 6Plus in fullscreen is 736x414 but the resolution is #x3 then the UIImage in the UIImageView have to be 2208x1242 because the size in points is 736(#x3)x414(#x3), no ?
Then in a general case, i only need to know what is the size of my UIImageView and if the resolution is #x2 i multiply the size x2 and if the resolution is #x3 multiply the size x3?
Guys i really need a confirmation and if i'm wrong, please, explain me why !
I'm sorry if you think my question is really stupid but i need to understand how it works.
Cordially :)
Lets go for a ride of #1x, #2x and #3x image scaling and content viewer size according to different resolutions in iPhone.
Let understand some basics first
Device Resolution
================================
iPhone 4 & 4S 640×960
iPhone 5, 5C & 5S 640×1136
iPhone 6s 750×1334
iPhone 6P 1242×2208
Resolution reference from this site.
Now if how to use images with #1x, #2x & #3x.
Lets say you have an imageView in with size of 100W x 100H, to display images properly on all the devices with appropriate resolution without stretching or pixelation your image, one need to create 3 set of images as below according to device.
iPad 2, iPad mini supports #1x images, required image of size 100x100(WxH)
iPad, iPad mini supports #2x images, required image of size 200x200(WxH)
iPhone 4S, 5 & 6 supports #2x images, required image of size 200x200(WxH)
iPhone 6P supports #3x images, required image of size 300x300(WxH)
Though your UIImageView size is 100x100 for all the devices, but image displayed in different devices is different according to their resolutions.
Following size Table will give you more clarification, read more about it in apple documentation here
I hope it clears confusion about different resolution images for different devices :)

How to cut iOS8 assets from a PSD designed at 1242px by 2208px

The designers on a project I am responsible for developing (one of my first iOS projects) designed the app using a Photoshop canvas set at 1242x2208 pixels, which is the number of pixels that the iPhone 6+ uses. I've scoured the internet and am just getting more and more confused by all the conversions for 1x, 2x, 3x and to further the confusion, apple downsizes to 1080x1920.
Anyways, how do I cut the assets correctly for #1x, #2x, #3x? When I crop the element I want, I save it out at 3x. But what do I divide by to get the 2x and 1x versions?
Here's secondary question and a hypothetical situation: There is a button that is designed to be the full width of the screen in portrait, so the designer made it 1242x100. If I save it out at 3x, then scale it down for 2 and 1x, will this button fit all the different screen sizes all the way down to iPhone 4/4s, which has a smaller pixel dimension and different aspect ratio?
Confused, any help appreciated!
Example:
If you original artwork is 960px by 1704px, just save you image including "#3x"
image#3x.png // (960 x 1704)
Then you have to resize it to 640x1136 and save including "2x"
image#2x.png // (640x1136)
And then you have to resize it to 320x568 and save as 1x
image.png // (320x568)
Indeed the Retina sizes are confusing, but this is what auto resize is used for in Xcode.
But The API which Apple give us, chooses the #3, #2 and 1 sizes by itself. There isn't anything that the developer/designer needs to do but provide all three images. An example is:
ObjC:
+ (NSImage *)imageNamed:(NSString *)name]
Swift:
init?(named name: String) -> NSImage
Would just use the name of the image without the # etc... So, myImageName#3x.png myImageName#2x.png myImageName.png would just be referred to as "myImageName"
The API handles the rest :)
I have had the same problem. What I did was, after cutting all images for iPhone 6+(#3x), I just resized the PSD to iPhone 5's width which is 640px, (height would be 1138 px if you keep aspect ratio) and cut #2x images. For the 1x images, again resized to 320px width.
Just, iPhone 6+, iPhone 6 and iPhone 5 have almost same aspect ratio.
Good Luck!

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.

Using Non-Retina UIImage for Retina display device

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.

Resources