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).
Related
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.
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.
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/
Google Play allows different apks per screen density, does Apple Store support this?
I'm sure the info is somewhere, but all I find when I search are people asking how to develop one app to support all devices.
I know how to do that already, but this specific (top secret) project will be 1000 times better if I can release one super optimized version for each screen resolution... but I'll settle for density or device (generation and type) if needed.
I don't have access to XCode (no Mac) to check options currently.
Bonus points: If possible, is Apple going to frown on this and possibly reject my app because of this?
This can't be done. If your app supports the iPhone then it must support both 4" and 3.5" inch iPhones. If it supports only iOS 7 then you can avoid non-retina devices because only retina devices can run iOS 7.
But if you support the iPad you must support both retina and non-retina.
You can have one app (Universal) that does it all or you can have separate iPhone and separate iPad apps. But the iPhone app must support both sizes and possibly both types (retina and non-retina) of screens. And the iPad app must support both types of screens.
Apple won't accept apps that don't support the differences.
It should also be pointed out that in the Interface Builder part of Xcode, you setup the UI with points and not pixels. So, for an iPad, when you place a button, you do not have to specify retina or not. On a Retina screen a point is 2x2 pixels and on a non-retina screen a point is 1x1 pixels. Also, with image assets, you have a single image asset you ask for in code, but you add multiple copies of the image in the image assets. Like the retina and non-retina copies. If you have an image named cat.png, for retina this would be cat#2x.png and for non-retina it would be cat.png. But, in code or the inspector you would reference it with imageNamed:#"cat" and Objective-C is designed to handle the rest.
I am creating an application for iPad, the images I have available from graphic designer are
really big, almost twice the size.
According to the graphic designer, the images were created keeping in mind iPad 3.
So if I reduce my image size to half and use them, is it going to make any difference on iPad3?
Or there is no difference and it will be compatible in both.
I am new to iOS development and not sure about the image resizing in detail.
Thanks in advance.
You will have two versions of every image where one is double the size of the other and the operating system will decide which version to use. You just need to name the images correctly.
Images for ipad3 will have #2x within the name. Example
image.png <--- non retina ipad
image#2x.png <------ retina ipad (ipad3)
Here is a post explaining this more: Preparing your iPhone App for Higher Resolutions