How to set Background Image correctly - ios

I want to set a background image to my app but the image is not centered. The resolution is 640x1136, I have only one size, do I need more ? What is #2x and #3x ?

EDIT
I ended up spending ~ an hour in chat with the OP, and the solution to their problem was ultimately to remove all launch screen assets from the xc bundle and instead just put a UIImageView on the launch screen storyboard, anchor each side of it to the sides of the view, and set fill mode to aspect fill. That said, the below information is more likely to solve the problem for the majority of people who run into this, I think.
You need different sized images for the different screen sizes & aspect ratios. From the Apple docs:
It’s best to use an Xcode storyboard for your launch screen, but you can provide a set of static images if necessary. Create static images in different sizes for different devices, and be sure to include the status bar region.
The documentation includes a large table with all possible screen sizes one might support.
Many tutorials exist on the topic, and they may be a good place to start. This similar SO question also has a number of useful and informative answers.
Personally, I make one high-resolution image and then drop it into a tool which automatically generates all necessary screen sizes for me. I do the same thing for all the app icon sizes. Many such tools exist; SO is not an appropriate place to pontificate on which tools are better than others, so I will leave that choice (and research) up to you.
As far as where to put the images, the following instructions from Matthew Palmer's tutorial should be sufficient to get you started:
1 In Xcode, Click on your Assets file (Images.xcassets) in the left sidebar. It should open in the main pane.
2 In the left sidebar of the main pane (where AppIcon, LaunchImage, etc. are), right click
3 Select New Launch Image
4 Add your new launch images as normal. If you want something quick and easy to use, Paul Haddad recommends taking a screenshot in the iPhone 6 simulator and using that, or DavidSmith has created some default ones.
5 Change the Launch Images Source from your Target’s settings.
I found a useful list of launch screen resolution sizes here, which I will quote below:
Image Resolution Image name
320x480 Default.png
640x960 Default#2x.png
640x1136 Default-568h#2x.png
750x1334 Default-667h#2x.png
1242x2208 Default-736h#3x.png
768x1024 Default-Portrait.png
1024x768 Default-Landscape.png
1536x2048 Default-Portrait#2x.png
2048x1536 Default-Landscape#2x.png
The link where the above table was quoted from is also probably the best tutorial I was able to find on the topic. Note that, if you make the larger sizes first and drag them into Xcode, Xcode and auto-generate many of the smaller resolutions for you. (For example, providing one iPad resolution will typically be sufficient for all iPad resolutions.)

Ok let's take this one question at a time...
Background Image not being centered, I assume you have an ImageView containing that image... If so you should be able to do something like imageView.contentMode = .center
The #2x and #3x are for the newer phones with higher resolution. It is advised to have all 3. Also if you could show any code that would help.

Related

Assets.xcassets - Universal not working

I am using Universal for Assets.xcassets in the hopes that I only have to create 3 different sizes for each image I use. But, despite Assets.xcassets telling me that my images are Universal in the Attributes Inspector, when I test on my iPad, the images are blurry and aren't as sharp as they are on my iPhone, making me question why there is a Universal option.
I've double checked all my images and they are all correctly sized.
My questions:
In the Attributes Inspector, under Universal, there are iPhone and iPad options. In order for my iPad to provide crystal clear images, should I use the iPad option?
And if I should: What's the point of the Universal option if it doesn't really do its job?
Also if I should: What size images do I use. The iPad option gives me the options of 1x and 2x size images. So, should the size of the 1x image for iPad be the same size as 1x image for Universal?
Thanks in advance.
Universal merely means that this app will run on iPad and iPhone natively. Thus the devices on which your app might run can have a single-resolution, double-resolution, or triple-resolution screen.
If you have checked Universal, accordingly, you should see three slots:
Your job, therefore, is to make three versions of your image, sized in proportion. If the 1x is 100x100, the 2x should be 200x200 and the 3x should be 300x300. The version in the appropriate slot will be used at runtime in accordance with the screen resolution of the device we're running on.
The asset catalog does not do any image sizing for you. You have to do it beforehand. (I find Graphic Converter a nice utility for this purpose.)
You could just supply a 3x image and allow the runtime to size down for you, but this is a waste of memory; Apple specifically advises against this in one of the WWDC 2016 videos. So just bite the bullet and make all three image sizes yourself.
Finally:
when I test on my iPad, the images are blurry and aren't as sharp as they are on my iPhone
Hmm, the only reason I can think of for this is that your app is not running natively on the iPad, but is an iPhone app running in "emulation mode" on the iPad. If that's the case, nothing you can do is going to make it look really good. It would be better to write your app as a true Universal app. That is a setting that you make when you create the project initially (though it can be changed later by editing the app target).

Adding iOS #1x, #2x, #3x PER device, how to?

I recently asked a question about why we use the 3 different image types listed above, and got good/detailed responses. It also lead me to question something else...
Assume I am working in XCode (with SWIFT) and have the three image sizes #1x, #2x, #3x for a particular say UIImage on an iPhone. Now, I want it to look nice on iPad, so I add some scaling. However, this will change the sizes of the 1x, 2x, 3x images I need for the iPad, so I need to make 3 more to compensate for that new size. Now how will XCode differentiate between the two? Do I need to check what size screen I am using and then choose the images?
I read that assets could help me, but that only deals with iPhone vs. iPad, what if I scale my images across iPhone 4, 5, 6 and iPad. That's a lot of different sizes and #x images, and I read Apple doesn't like device checking so I'm not sure how that would happen.
I hope this makes sense. I get the #1x, 2x, 3x per device, but if my app is being designed for universal device use, then how do I manage all of these different sizes in code for the proper device?
You really should use image asset catalog. It makes it almost too easy. Here is the definition Apple gives so you know it's not hearsay:
Image sets: Used for most types of images, an image set contains all the versions, or representations, of an image that are necessary to support various devices and scale factors.
And it goes on further:
Each set in an asset catalog has a name. You can use that name to programmatically load any individual image contained in the set. To load an image, call the platform specific class method, passing in the name of the set that contains the image. The OS will load the image from the set that is most appropriate for the current scale factor
So there really is not much for you to do. I don't know where you heard the opposite
See Documentation here
You need to check the size of the biggest image, if you are using an iPad figure out the size of the UIImageView frame. For instance if it is 400*400pts then your image will be 1200*1200. Just use a single image. I don't think you need to include the #2x and #1x. The 1200*1200 covers your bases for the largest possible image and scaling down will still have plenty of pixels left over for the full #3x resolution on other devices and so on. This is how I understand it anyway. I also wondered this myself and only found #1x #2x #3x useful for things that I didn't scale up as the screen size increased such as some buttons.

Photo Size and Resolution for iOS app

I am working on an iOS application that will show photos either in full screen or in frames in various sizes - like product catalog.
I know I am supposed to use images.xcassets to make things simple and I know I am supposed to create more than one version of the same photo in different sizes.
All I can find is AppIcon and LaunchImage guidelines. What would be the rules I should follow preparing photos to show in different devices? Sizes, resolutions?
Sample: I have 2048 x 1536 raw sized photo (even bigger ones). When it comes to prepare it for iOS app (will work both in iPad and iPhone), what are the dimensions to export my photos from PhotoShop? What would be the biggest sized version?
Could someone please show me a starting point to understand this?
Thanks in advance.
This design guidelines guide is very good. You will find everything you have to know about sizes.
But the simplest way is to use a tool like Asset Catalog Creator to generate your assets. Just drop your original image in it, select your #1x size, and it will generate the catalog for you, for all sizes.
Here is a screen size reference for iPhone devices you may find helpful. Here's one for iPads.
Additionally, if you've got a lot of files you need to resize that you've already exported, you might consider using ImageMagick for batch resizing.

Images.xcassets in Xcode 6

I am trying to figure out how to use the xcassets folder in Xcode 6 and I have to say Apple could have done a way better job. I'm a big fan of Xcode but their images storage per type of screen / phone is a nightmare.
First, in my application I am using images which will have a height of half their width. From what I understood, taking pictures of around 1200x600px should do for all types of iphones (full width minus small margin). So I put them in 3x universal, right? If I gave the maximum size why would apple need 1x and 2x ...? Just resize it yourself, no? Is it compulsory for me to give something or will it work by itself? Images are not vector but simple PNGs. In the simulator nothing is complaining and it works well for all types of iphones. Is it okay to leave the other two empty? From I see from the simulator iphone 6 will use downsized #3x images so what is the point of having two images? Only ratio is important and they have the same ...
Secondly, I just added today a launch screen for retina hd 5.5 / 4.7 and now when I run the app in the simulator my uitableviews only take around 4/5 of the full width instead of full width .... can't figure out why adding a launch screen would modify layout of my uitableviews ....? Navigation bar and other screens seem untouched though ...
Any help appreciated.
you need to add the images for the 2x & 3x because when you add large size image then at the run time this image get resize as per the actual width of the image it utilize memory lots of memory to do this & some time if your application have too many images then you will get memory issues
if you want to test this then run your application in iPhone 5 then see the memory utilisation by first keeping the high resolution image now take image which will be of appropriate size to iPhone 5 & then run again you will see the difference
so the best practice is to use different image for different size & not images in this fashion.
The answer to your second Question
if you are not adding the splash screen for iPhone 6/6+ then iOS stretches your UI of iphone 5 to fit into the size of the iPhone 6/6+.
But when you add splash screen it stops doing that.
late to the party but yes you need to manage all this resolution by yourself. Otherwise it will consume more memory.
but yes there is one tool which will make your work less by generating all assets for you
AVXCassets Generator

iPhone 6+ images

I have a question that I need confirmation on. I know that the Apple Developer document shows App icon size at #3x
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/IconMatrix.html.
Does this also apply to regular images that you use in your App? I just need to make 100 percent sure. The other stackoverflow answers I encountered just show App icon sizes, but doesn't address regular images that you use through out your App.
If you want your app to take full advantage of the Retina HD display then yes, you need to have all versions for all images used by your app, i.e. image.png, image#2x.png, image#3x.png.
Dont forget to setup launch screens for each iPhone size, or your bigger phones will just enlarge your app views without really using AutoLayout or using the high def images.
It doesn't apply for regular images that you use in you app. Make sure they are with good pixels.
Provide high-resolution (#2x) versions of all image assets.
Images that are not #2x will appear blurry on the Retina display.
source:
https://developer.apple.com/design/tips/

Resources