Where to store images in iOS project - ios

I'm new to iOS development. I have created a simple iOS app where I have many buttons with images inside. Also cells of UITableView in my application contains images.
Up to now I have put all images for buttons and cells in the "Assets.xcassets" folder. The images can also be accessed if I locate all images in separate directory (let say "Images" folder).
Where is the correct place to locate images? As far as I know in "Assets.xcassets" app logo, tab bar icons can be located, but I don't know is it allowed to store all images in that folder.

You can store any resource you like in the Assets.xcassets folder. Simply drag and drop the images into the Assets.xcassets folder and use them. There is no limit to what type of asset you put in the Assets.xcassets catalog. Of course, you can add a new asset catalog. It can be found in File > New > File, scrolling down to Resource and then clicking Asset Catalog. It acts the same as Assets.xcassets and the usage is the same.
For example, if you put an image called foo in an asset catalog called Bar.xcassets, you can still use
UIImage("foo")
without specifying the name of your catalog.

In general you should use assets for all static images you have in an app. Assets were introduced for a better handling of images with different resolutions for different devices (like #2x, #3x for retina devices). When user installs the app not all versions of the same image are downloaded but only that one that fits the best user's device. So your app will take less space which is good. Also assets are more convenient if you have several versions with different resolutions for the same image.
If you want you can place images in several assets. To add a new asset go to File > New > File and choose Asset Catalog in Resource section.

Related

Assets in asset catalog inaccessible to storyboard

I am migrating a project to iOS 9, and I want to place all my images into an asset catalog to take advantage of app thinning.
So far I have created an asset catalog in my project with all the images in the project, and I have removed the individual image files from the project.
The app runs, and on the simulator the images appear, but when I look at the storyboard, there is now a blue "?" box where each of the images should be.
How can I get the storyboard to recognize the assets in the asset catalog?

where did the icons/launch image table go in xcode 6?

If you look at this thread
iOS 7 App Icons, Launch images And Naming Convention While Keeping iOS 6 Icons
You see that xcode used to show a nice table where you could see all icon/launch image dimensions, what is missing etc.
I just managed to start migrating our app to ios8/iphone6 so i also upgraded xcode. However, now i can't seem to locate that table anymore, all there is is an empty section with buttons to "use asset catalog":
So, i have 2 questions:
is the table somewhere else, or is "asset catalog" the way to go now?
I tried the asset catalog, and all images are copied into this xcassets catalog. Is there any reason for me to keep the original files in the project? Do i need it for anything else, like ios5? I looked around but found no answer.
Thankful for some pointers.
Use the Asset catalog , this is the preferred way now.
If you use the asset catalog, all the images will be copied to images.xcassets, there is no need to keep the original files. If you control click the assets and show in finder, you could find the copied images. In asset catalog you have options to give different images for iOS 5,6,7 landscpae or portrait whatever is appropriate for your app.

Xcode not finding images from atlas folders when running

I have an app created in Xcode which has loads of images. To make it slimmer i created folders within Xcode as .atlas and made sure that these contained the (*.png) images i wanted.
from the storyboard and XCode navigator i can see the png files, and the UIImageView objects show the correct image selected from the dropdown.
so there is no problem with the images being accessed, and no issue with file name.
When i clean/build/run the app through the iPhone simulator no images show the outcome is blank...
There are a bunch of different reasons why this could be the case.
Here are a lot of answers that worked for some.
http://solvedstack.com/questions/could-not-load-the-image-referenced-from-a-nib-in-the-bundle-running-on-device
In my case i had the same setup you described.
One Texture Atlas and i wanted to use some of the pictures in there in an UIImageView.
I assume since TextureAtlas is mostly meant for SpriteKit, i added my Pictures that i wanted to use to the Images.xcassets folder.
Then the preview in the Storyboard works as well as on the device.

XCode5 won't accept all my icons and launch images

After switching to XCode5 I've just re-done all my icons and launch images for an app, with the exception of retina launch images I should have a complete set for both iPad and iPhone, iOS6 and iOS7, thanks to this tool: http://www.appiconsizes.com/
But XCode5 absolutely refuses to use them all. I removed all the old images from my project and added the new ones. Some, XCode automatically detects, seemingly at random. Many others, it says it can't find the images needed even though they are named according to Apple's guidelines (as far as I can see, it's all a bit confusing with so many variants). It lets me find them manually but doesn't seem to be using them properly.
And my launch images, it insists on using images from a different target even though these are definitely not marked to be included in this target. It won't even let me change those ones, if I try to then it just ignores my selection.
A few screenshots follow. I originally had just an "Icon" icon identifier in my plist, since Apple say it will automatically detect different variants, but XCode has then added Icon-76 and Icon-120, seemingly contradicting this. I'm aware XCode5 supports controlling things more through your plist than XCode4, but shouldn't require that - you should be able to tell it the icon base name or use "default" and it would figure things out?
Use an asset catalog for your project.
It has placeholders for the launch image and the icon and each one tells you which size it needs.
Much easier than handling lots of dirrefent files in different locations.
In the project info page there is a button that says "use asset catalog". It will import all your images for you. The code doesn't change when using an asset catalog so it will all still work.
Another thing with asset catalog is that the name of the files doesn't matter. You just drag the image to the slot you want it to go into. With icons and stuff there is only a size restriction.
Even for retina images you don't need the #2x before because there is now a slot for "standard" and "retina" images.
I guess the problem is in Your icon Name,
for iPhone retina Name should be Icon-60.png , Icon-60#2x.png
So as Fogmeister suggested use asset catalog
Like
So its like

Why won't image import into iphone app's asset catelog using xcode?

I am trying to create a launch image for my (first) iphone app. I have done the following:
created 2 PNG images for this purpose.
one image is: 640 x 960 pixels
the other is: 640 x 1136 pixels
added the above 2 files to my project, under "Supporting Files"
In the asset catalog, I select my "LaunchImage" image set, and set its attributes to only support iPhone Portrait, iOS 7 and above
I try to drag each of images mentioned above from "Supporting files" into the 2 place holder images (Retina and #2x). The images are not accepted. I do not get an error, but the images are never drawn, and the image is not used when the application launches.
If instead I try to import the files by selecting "import" from the context menu, I get the same behavior. No error, no image.
Do I need to do anything else? Like follow a naming convention?
Per what I have read, the names of these files no longer matter - though I have tried naming them:
LaunchImage.png (640x960) and LaunchImage#2x.png (640x1136). This has not made any difference.
Any help would be greatly appreciated.
Just change the file extension from "PNG" (upper-case) to "png" (lower-case). I spent a couple of hours futzing around until I finally figured out that was the issue!
Note that screenshots taken with a physical iOS devices have "PNG" extension, and will never work until you change the extension. But screenshots taken on the iOS Simulator have extension "png" and work fine as is.
I've logged this in the Apple Bug Reporter as an XCode Usability issue:
17676619 Can't drag "PNG" to LaunchImages; only "png" works
Have you tried dragging the images straight from the Finder into the Asset Catalog? You shouldn't need to drag them into your project as an extra step first.
The other thing to check is that they are definitely PNG images; the Asset Catalog doesn't accept JPGs.
Had the same issue today. It happened only with a single image.
To solve it you have to re-save your image using a picture editor (Preview for Mac).
Launch Preview
Open your image
File -> Duplicate
Save it as another file
Drag and drop new file into asset catalog -> it works!
I was finally able to import the images. I must have messed something up prior, as I am certain that what I had to do should not have been necessary. But, in case anyone else runs into a similar dilemma:
I deleted the "LaunchImage" image set from the assets catalog
In the build settings, I changed the Asset Catalog Compiler Options to not have any image set named as the launch image.
In the assets catalog, I then created a new launch image set, using the context menu option "New Launch Image".
I was now able to successfully import both my images.
At this point, my app finally had a launch image - but it was the wrong one (i.e., 4 inch). This got fixed when I:
Changed the Asset Catalog Compiler Options (in the Build Settings) to again specify the "LaunchImage" as the launch image
catalog
FYI: I had previously tried adding a new launch image set, but had still never been able to import my images. It seems like the trick was to change the compiler options - but I have no idea why.
Not a substantially different answer, but just for someone who needs something more explicit, my images were saves as .jpg, which will not work. Open the photo editor of your choice and save as .png.
It’s back. In Xcode 10.2 dragging an image into an asset Catalog only works with one image. Then you need to close the project and open again to add another image.
They display in the catalog, but if you right click and Show in Finder, the image is not copied to the catalog folder. When you close and open only the first one remains.

Resources