Software Access Program Catalog

I know this is a new feature and it may not be possible, but I would like to be able to use the asset catalog to organize my assets, but I get access to all my images programmatically. How do I access my images now? Should I still access them by file names as follows:

[UIImage imageNamed:@"my-asset-name.png"];

It seems that the resource directory does not reference the extension, so it would be more efficient to access it without ".png"?

The reason I ask instead of checking for myself is that even after deleting my assets and assets catalog and then cleaning the build folder, I can still access my assets in my application. This prevents me from checking the asset catalog when I implement it.

After looking at the asset catalog, I found "Contents.json" for each asset and is formatted like this:

 { "images" : [ { "idiom" : "universal", "scale" : "1x" }, { "idiom" : "universal", "scale" : "2x", "filename" : "my-asset@2x.png" } ], "info" : { "version" : 1, "author" : "xcode" } } 

I'm still not sure how I should contact him, but maybe this will help?

+73
ios objective-c xcode assets
Jun 11 '13 at 19:39
source share
3 answers

To access the image from the asset catalog, you only need to access the name of the asset group without any extensions.

So, if you add an image named @"my-button@2x.png" to the asset catalog, it will create an asset group called my-button .

Now all you have to do is access the image like this:

 // Objective-C [UIImage imageNamed:@"my-button"]; // Swift UIImage(named: "my-button") 

In addition, you can edit an asset group by renaming it (without renaming images) or by changing its individual components. This will allow you to follow simpler naming conventions, and also show completely different assets between different UIScreen scale without any scale checks.

To include images for different device sizes, you may need to switch it in the β€œDevices” sub-heading in the parameters of the asset catalog group. Here is an example of this switch (available by right-clicking on a group).

+108
Jun 12 '13 at 17:01
source share

Swift

You can get a link to the image in your catelog resource using

 UIImage(named: "myImageName") 

You do not need to enable the extension.

+1
Aug 11 '16 at 17:05
source share

@RileyE is 100% right. However, from my experience it is also worth noting that sometimes a link to a resource catalog for an image may contain finite empty space. You probably won't notice that using the / xibs storyboard when autocomplete adds it. But when you reference it from code, it is not so obvious what the problem is.

0
Jun 16 '15 at 17:47
source share



All Articles