iOS Swift Using image.xcassets VS dropping image in xcode folder - ios

In the last 6 months I have been able to make a pretty good app in iOS Swift. But Now I want to touch upon some performance and best practices in development.
So I wanted to know what is the best practice of using images in Xcode? To be specific, I usually drag and drop images in my project folder to use it inside my app. But I know that we can also use image.xcassets to do the same thing.
The question is, which one is the right way? Or which one should be used when?
I have seen in image.xcassets we have to provide 3 images. 1x, 2x and 3x. Does that mean that I am increasing the size of the app (considering I am using many images)? Also how does it effect the performance? Is there any difference in fetching the file from project folder or from image.xcassets?

On the top of my head "Image.xcassets" has a bug in Xcode 6 where you cannot load JPEG images. Other than that, it is the best practice of organizing your images. The 1x, 2x, 3x are for the different screen resolutions of iOS devices. 3x images load on iPhone 6 Plus, 2x on any device with a retina screen (iPhone 6, iPhone 5/5s/5c, iPhone 4/4s, etc), and 1x on some of the older iPads and iPhones

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).

do I need to include #1x images of app only runs on iphone 4s and above?

Is this still necessary? 2x and 3x seem to be the only images I need based on models I support. What is the correct approach?
If your app is targeted for iOS9 or less then you still have to build for the iPad 2 which does not have a retina display.
http://www.evad3rs.net/2014/10/ios-9-supported-devices-compatibility.html
Even if you're building an iPhone only app they will run on an iPad.
You cannot restrict your app by device. So if you're supporting iOS9 or less (which is every OS version) then you should include #1x images for this reason. If you don't then the #1x devices will just display scaled down versions of the #2x images so you don't NEED to include them... but you should.
What you can do instead (which is something that I have been doing more and more recently) is to use an app like PaintCode. This will take your images and turn them into code. This code is then imported into your project and the images are generated at runtime by the code. They are completely resolution independent and it reduces your app bundle size as you don't have to bundle in any images.
According to IOS Human Interface Guidelines all IOS high resolution devices below IPhone 6, use 2x form of images. So if your app will not run for non-high resolution devices, I am guessing you don't have to add 1x version of images.
Here's the thing, apple reviewers always test your app on the latest and greatest device. They will certainly test your app on BOTH iPhone and iPad using the latest hardware. They don't have time to regression test your app on every possible device (ipad2, iphone3, iphone4, iphone5 etc). Your users on the other hand will let you know when things don't work as not everyone is on the latest hardware.
Now when you create a project you are required to provide icon images. I am sure you know this screen in Xcode. You can see there are places for 1x images. What happens if you don't provide 1x images? Go ahead, archive the project and try to upload to itunesconnect. You will most likely get a validation error that certain images are missing.
Like other said you cannot restrict your app from running on iPhone 4 Vs iPhone 4s and your binary will be stopped from upload if any required images are missing.

iOS image resolution sizes with Sketch 3

I'm trying to understand the different image asset resolutions in Xcode/iOS development and I can't seem to wrap my head around it.
I use sketch 3 to develop the images I use in my apps.
So let's say I have an art board set up at the iPhone 5 size. I've used this art board to create my images at the sizes I want them to be when displayed on an iPhone 5. Would I export these images as 1x or 2x?
I've read that the iPhone 5 and 6 use the #2x resolution but this is where I start getting confused. If I've created the images at the iPhone 5 dimensions would I really want to up the pixel count?
Any clarification would be much appreciated!
All Artboards are in 1x resolution.
When you export you should be doing it at 2x. For iPhone 6, 5, 4.
You should really be exporting all your assets at all 3 sizes since iOS 9 still supports the older 1x on iPad 2 (should your app also support iPad)

iOS: minimum image resources necessary for ios application using size classes

This question might be a duplicate, but I couldn't find any reasonable answer.
I am developing an app that supports all iOS devices, for which I have to import image resources for every device.
If I use image optimizer, it will destroy quality of images.
Currently my app consists of iPhone 5, 6, 6+, iPad and iPad retina images, which costs me about 20 MB space in my application.
How can I reduce this size? E.g. by removing iPhone 5 or iPhone 6 images, will the application work fine or not?
This will all entirely depend on the design of your application. #3x graphics are for the iPhone 6+ only (for now), and the resolution on the device is so high some users might not notice that the #3x graphics are missing. You might also be able to "re-use" some of your iPhone graphics for the iPad (for example you could use the iPhone #2x graphics for the iPad non-retina). But again, depends on your graphics design.
I don't know how you use this images, but
If you want reduce the size of your app there are, for me, two solution.
Check if the size of your images are not too big (the size of your UIImageView x2 will be enough).
Get the images by downloading the right image and store it in the device.
No, you have to store iPhone 5,6,6+ startup images just to disable scaling.
Remove redundant orientations from startup images.
Try to use ImageOptim to minimise png images. It uses lossless optimisations.
Try to use lossy optimisations for images if they are still too big.
If you use clean background in your app, save startup images with only background colour without UI, and make sure that app start fast. It will look OK.

iPhone 6+ using #1x images

In an app I am working on, iOS seems to be choosing the #1x images over the #2x images to display on an iPhone 6+ (picks #2x properly for a normal retina 2.0 scale screen). It was not always doing this though. I am not sure if the trigger was me adding a few #3x images or upgrading to 8.1 - both were done on the same day and I did not test on device until both had been done in several places.
Anyone else seeing this?
I'm having a similar issue with the iPhone 6 Plus running iOS 8.1, built with Xcode v6.1. The problem affects images used from the bundle, but doesn't seem to affect those in an asset catalog.
If only the 1x image is available, it uses the 1x image, as expected.
If only 1x and 2x are available, it strangely uses the 1x instead of 2x.
If 1x, 2x, and 3x are available, it uses the 3x, as expected.
I put together a quick asset test that I've uploaded to GitHub.
A workaround is, to set the images via myImage=[UIImage imageNamed:#"foo.png"];
Like so, the #2x images are taken, when no #3x is available.
You can do this recursively for every screen.
iOS 8.1.1 resolved this. It was clearly an iOS bug that Apple has now fixed!

Resources