Access Asset Catalog pathForResource

后端 未结 6 1299
滥情空心
滥情空心 2020-11-27 17:46

It appears that:

[[NSBundle mainBundle] pathForResource:@\"name\" ofType:@\"png\"];

Does not return anything for assets that are inside the Ima

6条回答
  •  隐瞒了意图╮
    2020-11-27 18:31

    Same problem, but I don't think we could access it via pathForResource:, except below:

    UIImage* image = [UIImage imageNamed:@"name-in-asset-catalog"];
    

    It has been clearly documented:

    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 UIImage:imageNamed: method, passing the name of the set that contains the image.

    I found that in the package of complied app, a file named "Assets.car" came out, and I think it's the entire images sets in my project, and should have been zipped or something.

    Refer to Apple's documentation:

    Xcode 5 provides different functionality for asset catalogs depending on the deployment target for your project:

    • For all projects, individual images can be loaded using set names.
    • For projects with a deployment target of iOS 7, Xcode compiles your asset catalogs into a runtime binary file format that reduces the download time for your app.

    So that's it.

    I'm also looking for a way that doesn't use imageNamed:, I don't want runtime to cache my images.

提交回复
热议问题