Ios image size guide for different iphones - ios

I am just confused about the image sizes that I need to use for buttons, image views etc.
I want to adjust images for all iphones.
What should be ratio between the screen height/width and different iphones.
Like i have a button. I have created in following way-
UIButton *takePicButton = [UIButton buttonWithType:UIButtonTypeCustom];
takePicButton.frame = CGRectMake(0, SCREEN_HEIGHT-UI_ITEM_HEIGHT, SCREEN_WIDTH, UI_ITEM_HEIGHT);
[takePicButton setBackgroundImage:[UIImage imageNamed:#"take_photo.png"] forState:UIControlStateNormal];
[self.view addSubview:takePicButton];
[takePicButton addTarget:self action:#selector(takePicture:) forControlEvents:UIControlEventTouchUpInside];
for this button what size of images I need to add on xcode to support iPhone 4 - iPhone 7.
Thanks in advance.

Here is description about how image can set in iPhone:
• 1x images are for the original iPhone through the 3GS - 'standard' resolution devices (3.5" screens)
• 2x images are for the iPhone 4 and 4S (3.5" Retina screens) and are also used for the iPhone 5, 5s,6,6s,7
• 3x images are for the new iPhone 6+,7+ (5.5" super-Retina [3x] screen)
You have to keep three different types of image into your Assets.xcassets and just provide image name at where you want to display it. It will automatically take relevant image and display it.
You can check attached screenshots. You just have to write “bgImag” and it will take relevant image from assist.
About image ration, just create image for highest resolution of iPhone (i.e iPhone 6+), and just use iConify to get rest of image assest.

Try this, u can ask for two sizes. One is SCREEN_WIDTH * 2, UI_ITEM_HEIGHT * 2, the other is SCREEN_WIDTH * 3, UI_ITEM_HEIGHT * 3.Then put two sizes pics in your Images.xcassets named xxx#2x, xxx#3x.

I want to adjust images for all iPhones.
The easy way to do that is to use layout constraints. Your code tries to do what the constraints system would, given an appropriate set of constraints, but it's less flexible because it doesn't provide for changing geometry such as when the user rotates the device.
What should be ratio between the screen height/width and different iphones[?]
Different devices have different aspect ratios. There are lots of web sites (like this one) that list the screen sizes. When possible, though, it's best not to make any assumptions about screen size. New devices may be introduced with different aspect ratios, and even a single device may appear to have different screen sizes depending on how the user chooses to use it -- things like rotation and split screen affect the size and shape of the screen real estate that your device gets to use.
for this button what size of images I need to add on xcode to support iPhone 4 - iPhone 7[?]
We can't say without knowing what your UI_ITEM_HEIGHT constant is or what relative proportions you want for your button, but you should be able to calculate that yourself if you know the various screen sizes. You can use the reference I linked above, or this one, or one of the many others out there.

Read guide line for 1x, 2x, 3x

You should simply use:
UIImage *imButton = [UIImage imageNamed:#"image.png"];
[YOURBUTTON setImage:imButton forState:UIControlStateNormal];
Xcode will automatically use the available image with scales ex: #2x or #3x
From my example your images would be:
image.png (20x20 px),
image#2x.png, (40x40 px)
image#3x.png, (60x60 px)
respectively.
Quoting from apple:
Image Size and Resolution
iOS uses a coordinate system to place content onscreen. This
coordinate system is based on measurements in points, which map to
pixels in the display. On a standard-resolution screen, one point
(1/72 of an inch) is equal to one pixel. High-resolution screens have
a higher pixel density. Because there are more pixels in the same
amount of physical space, there are more pixels per point. As a
result, high-resolution displays require images with more pixels.
Refer here

Guys
You can try below code:
if (IS_IPHONE4) {
imgHeight.constant = 150;
}
else if (IS_IPAD) {
imgHeight.constant = 300;
}
else if (IS_IPHONE5) {
imgHeight.constant = 170;
}
else {
imgHeight.constant = 200;
}
Thanks.

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.

What is a good approach for scaling/drawing images for different screen sizes?

In my iPhone app, I have a control that takes on quite different sizes on different screens. For example, (in the iOS point coordinates)
3.5 inch devices (iPhone 4S): 242x295
4 inch devices (iPhone 5 series, SE): 242x383
4.7 inch devices (iPhone 6 series): 297x482
5.5 inch devices (iPhone 6 Plus series): 336x551
As you can see, these control sizes are not proportional.
The problem
This control has an image as its background. That particular image is important for brand identity and the custom appearance that my company's designer wants to go with. The image gives the appearance of a material and has a texture. It also has shadows within itself. I would like to apply this image on to controls of different screen sizes (my control sizes are determined at runtime according to available space, as Apple may come up with new screen sizes anytime).
My current solution
The designer makes separate PNGs for me for each screen size and I hard code it with onto my control using an if-else for screen size (after determining the size mathematically before hand). As you can probably tell, this is a horrible approach for robustness. I'm also looking to expand to iPad and having a better scaling system will certainly help.
An idea
I take an image that's the smallest unit of the repeating texture and apply it to my control with the scaling option that repeats it throughout to obtain a final image.
HOWEVER, I lose my shadows and rounded edges this way. (I tried simply using the largest image as well and the disproportionate scaling makes the rounded edges horrible)
I tried looking for solutions and most resources do not deal with such images. I simply cannot lose any part of this image and it should be fully applied to the control, shadows and corners included.
I apologize if any or all of this is naive or if I didn't look for answers using the correct words. This is my first time posting here at Stack Overflow, and I'm looking forward to hearing from you guys.
Thanks!
p
Edit:
This is applied to a custom UIButton based control to give the appearance of a card.
Edit 2: Wain seems to have suggested a perfect answer. I will try it and let everyone know the results.
I'd use tiling as you describe, and I'd combine that with changing the view layer corner radius and applying a shadow offset. In this way you can separate the important part of the image and make it nicely reusable and you can leverage the capability of CALayer.
Note that when you set the shadowOffset of the layer you should also look at the shadowColor, shadowRadius and shadowOpacity.
You can used Assets.xcassets for managing images in ios. you can make image in 1x,2x and 3x scale.
For example you want an icon of size 50x50 pixel then 1x should be 50x50,
2x should be 100x100 and 3x should be 150x150. then ios automatically take appropriate image from this set.
Hope this will help :)
The aspect ration of iPhone 5, iPhone 6 and iPhone 6P are almost same. however the aspect ration of iPhone 4 is different.
Here is the steps which helps you.
So you need one image which image is suitable for iPhone 5 and its
#2x, and #3x image and iPhone 4 and its #2x image,
i.e if you have image with 242x383 for iPhone 5 then you need images
with its #2x, and #3x images. and you need image which is compatible
with iPhone 4 size.
You need to set UIImageView's contentMode as aspectFit.
So the idea is, make iPhone 5's image and its #2x, #3x images and iPhone 4's image differently. or you can put all things in UIScrollView and for iPhone 4 set contentSize of scrollView is 568. and make different image for iPad.

What types/sizes of images do you need when using UIImage full screen?

I'm targeting iOS8 to release an application. So it'll be available on 4S, 5's, 6, 6+, and iPad 2+.
I have a ViewController where, I present a UIImageView that is the entire size of my UIViewController's View.
My question is... what sizes do I need the image in. Am I going to need it in a special size for each device? Or does the 4s/5/6 all use the same ratios for example, while the 6+ has its own unique ratio? Or do I just use 1 image size and let it auto scale it (or will that stretch/skew the image)?
Also, what's the minimal size the image should be? If it's smaller than the native size of the iPhone 6+ for example, won't the quality of the image deteriorate?
In iOS8, you can use different size classes for different screens
use this post to begin.
Also refer this for more info about using different graphics for varying resolution.
The image in Imageview in 4s/5/6 devices render at #2x while that in 6+ it renders at #3x.So take an image and name it as Demo#2x.png and other image for 6+ having higher resolution , name it as Demo#3x.png.So When the image is placed in imageview , It will automatically takes Demo#2x.png for 4s/5/6 and Demo#3x.png for 6+.
you need special size for each device by using image.xcassets.And this will help you alot -
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html

Correct Image and Font Scale on different Devices?

I have a simple view with a text and an Image. I ran this app on iPhone6Plus and iPhone5. Then I made a screenshot of both and enlarged the iPhone5 screenshot such that it matches the size of the screenshot from iPhone6Plus. Here is the result:
As you can se the size of the text the size of the image and there positions are not identical but they should be to look the same on different screen sized.
Here is an example of a weather app running on different screens:
As you can see the sizes and the positions of text and image are identical.
The image is loaded from asset catalog:
imageView.image = UIImage(named: "shower3")
self.view.addSubView(imageView)
imageView.center = self.view.center
I have only created a 128x128 image and put it into the #1x version in the asset cataloge.
Let me rephrase this. I run the wether app on iPhone5 make ascreenshot and iPhone6 make a screenshot. Then I resize both screenshots to the same size. Then I see that both fontsize as well as images dimension are exactly equal on both screenshots. This means that on each device font and image must have different dimensions. How can I do that?
How can I achieve that text and image have identical proportions on different screen sizes? How does the Weather App do it?
Images
I am the creator and one of the developers of the Swift Weather app. The app doesn't use three versions of images because I didn't make those images and it was a Pull Request from another developer. I don't have the origin images.
As #Daniil Korotin mentioned, iOS uses points to calculate image and font sizes. iOS uses let screenScale = UIScreen.mainScreen().scale to retrieve the screen scale and pick up the proper size (1x, 2x or 3x) of the image. If we don't provide the proper size of the image, for example, in SwiftWeather app, we have only 1x version of the image (as the screenshot below), iOS will upscale the image to render on retina devices. On iPhone 6 Plus, it actually does downsampling for 3x assets. Please have a look at iPhone 6 Screens Demystified. In some case, if you don't provide 2x or 3x images, on retina devices, the image upscaled from 1x may looks blurry. We should always provide 1x, 2x and 3x images if possible.
Fonts
iOS renders fonts according to the specified points. It will automatically convert the points to certain pixel based on the devices' screen scale (as mentioned above).
How can I achieve that text and image have identical proportions on different screen sizes? How does the Weather App do it?
The answer is Auto Layout
You can see we set constraints for the image view (used for the weather icon) as below.
The width and height are always 150 points, please notice it is points nor pixels. It will render the same size (for look and feel, not for exactly pixels) for different devices. For your first image (iPhone 6 Plus vs. iPhone 5), it looks different because maybe your simulators have different scale. A better way to check how auto layout elements lay on the screen is to use Preview in Interface Builder.
Open the main storyboard, and click on Assistant Editor. On the right hand side, select Preview (on the top left). And click the plus sign ( on the bottom left) to add different devices. You can see they are identical proportions on different screen sizes.
If you have any questions, please let me know.
Something maybe off topic
If I design the images/assets, I would like to use some vector base tool like Sketch to design the assets and export them to three different sizes. Please have a look my another project iOSAnimationSample. It has a Sketch file for the design.
Sketch design
Export assets to different sizes
In that case, iOS can pick up the proper assets for different devices.
The app you are referring to does not correctly support multiple screen sizes. The interface is scaled up to run on the 6 and 6 plus, which is why everything appears the same size.
Look at the screenshots from your app - the status bar is much smaller on the 6 plus. This is because it is supposed to take up less room on the screen. It's 20 points high on all devices.
Now look at the screenshot from the weather app - the status bars are the same size. Because the weather app does not support multiple screen sizes, iOS simply takes the smaller interface and scales it up to fill the screen.
If you want to achieve the same effect (which you shouldn't) then remove the LaunchScreen.xib file and use a launch image instead. But people don't buy larger phoned screens because they want to have the same content, but bigger. That would be achieved more cheaply by simply holding the phone closer to one's face.
You're supposed to take advantage of larger displays by allowing more content to be shown at once on the screen - more rows of data in a table, more text from a book, more images from a photo library.
In the case of a weather app the extra space should be used to display more rows of an hourly forecast or something, not just a larger version of a fairly useless icon depicting the type of weather.
I suspect it is only game support that means supporting larger screens properly is not already a requirement for app store submission. Supporting the 4 inch screen became mandatory quite quickly, you should expect a similar rule to be introduced for the 6 and 6 plus before too long.
If you want a specific element to always take up 50% of the width of the screen, or a label to always be the same size as an image, then you use autolayout constraints with multipliers. An autolayout constraint is of the basic structure:
attribute of A = (attribute of B * multiplier) + constant
Most of the time the multiplier is left as one, so you're just saying that this is 20 points to the left of that, or whatever, but you can use the multiplier as well, and say that A is the width of B, multiplied by 2 or 0.5 or whatever you like.
iOS uses points to calculate image and font sizes. On non-retina screen 1 point equals 1 pixel, on retina screens — 2 pixels, and for iPhone 6 Plus it is equal to 3 pixels (some downscaling is applied, though). If you want to scale the image and font based on the actual pixel size of the screen, you can get the number of pixel per point like this:
CGFloat screenScale = [[UIScreen mainScreen] scale];
The iPhone 5, 6 and 6 Plus screen aspect ratios are the same, while resolutions differ. If you want to simply keep proportions, then you have to pick a 'base' screen width or height (say, the iPhone 5 screen width, which is 320.0 points) and then calculate the proportion by dividing the actual device screen width (say, iPhone 6 Plus screen width, which is 414.0 points) by that 'base' width (414.0 / 320.0 = 1.29375). You can get the screen size like this:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
Dividing screenBounds's width by base width gives you the proportion. Then you just multiply all the sizes and margins with that proportion (1.29375 in our case for iPhone 6 Plus). Hope you get the idea.
P.S. A good guide to resolutions is here.
P.P.S. And in your case, as skorolkov mentioned below, the app just upscales everything for bigger screens (add/remove splash screens to enable/disable this upscaling).
UPD: Ok, now I see what confuses you. Here's the thing: when Apple initially released iPhone 6 and 6 Plus many apps didn't support their larger screens and bigger resolutions. So they decided that if an app lacks splash screens specifically made for those phones, it should use the iPhone 5 resolution.
That's why you get the exact same pictures after manually resizing screenshots: the system does that too. It simply takes iPhone 5 'picture' and stretches it so that it fits larger screens. The drawback is clear (and visible, especially on iPhone 6 Plus): the fonts and images are blurry and upscaled (system interface elements, like status bar, get upscaled too). So basically you get the iPhone 5 picture on all larger-screened devices (you can check that by taking a screenshot on an iPhone 5, resizing it manually to fit iPhone 6/6 Plus resolution and comparing the actual iPhone 6/6 Plus screenshot to it).
To be clear: that's the behavior you currently get, but it's not good. To keep everything properly scaled using the devices' native resolution, use the method I described above (manual multiplication) or autolayouts with equal height/width set to desired ratios for interface elements.
Weather App is using upscale mode to run on iPhone 6+. You can enable it by removing launch screens for 6/6+.
Go to asset catalog, select your launch image and unset 'iOS 8 or Later' checkbox in Attributes Inspector.
Screenshot - your app has this set
Screenshot from WeatherApp
in programatically (X and Y) we pre define the values in constant :
#define XScale [[UIScreen mainScreen] bounds].size.width / 320.0f
#define YScale [[UIScreen mainScreen] bounds].size.height / 568.0f
Then create UIImageView programatically
var imageView : UIImageView
imageView = UIImageView(frame:CGRectMake(XScale *someValue, YScale * someValue, XScale *someValue, YScale *someValue));
imageView.image = UIImage(named:"image.jpg")
self.view.addSubview(imageView)
based on your screen size we need to set Constant values. We use for iPhone5 and 4s screen.
You need to set Layout constraint to all the views to make them look at same places and sizes in all screens sizes provided that the aspect ratio of screens are same.
Have you tried to remove autoResizingfunctionality from view?
Click on inner arrow to remove autoResize view as per superview
First turn off auto layout, auto resizing and size classes in storyboard.
Click on Images.xcassets icon and select all your graphics. In attribute inspector set Devices property to "Device Specific" and set the checkbox checked against "iPhone" and "Retina 4-inch"
Place all your graphics in 2x image set. You may place a higher resolution image set for better results with iPhone 6/6+.
Design your view for a reference device say iPhone 5 (320x568 portrait).
In your viewDidLoad method paste the following code
self.view.transform=CGAffineTransformScale(CGAffineTransformIdentity,self.view.frame.size.width/320, self.view.frame.size.height/568);
And you will have same result on iPhone 5/5s, iPhone 6/6+.

Resources