访问资产目录pathForResource [英] Access Asset Catalog pathForResource

查看:112
本文介绍了访问资产目录pathForResource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来:

[[NSBundle mainBundle] pathForResource:@nameofType:@png];

不为Images.xcassets资产目录中的资产返回任何内容。我也尝试过:

Does not return anything for assets that are inside the Images.xcassets asset catalog. I also tried:

[[NSBundle mainBundle] pathForResource:@nameofType:@pnginDirectory:@Images];

[[NSBundle mainBundle] pathForResource:@nameofType:@pnginDirectory:@Images .xcassets];

但这些都不起作用。

有有没有人成功检索目录中资产的路径?

Has anyone had success retrieving paths to assets in the catalog?

推荐答案

同样的问题,但我认为我们不能通过 pathForResource:,下面除外:

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

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

显然记录


资产目录中的每个集都有一个名称。您可以使用该名称以
编程方式加载集合中包含的任何单个图像。要
加载图像,调用UIImage:imageNamed:方法,传递包含图像的集合的名称

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.

我发现在编译应用程序包中,出现了一个名为Assets.car的文件,我认为这是我项目中的整个图像集,应该是压缩的或者其他。

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.

参考Apple的文档:

Refer to Apple's documentation:


Xcode 5提供不同的功能对于项目的部署目标,取决于
的资产目录:

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


  • 对于所有项目,可以使用集合名称加载单个图像。

  • 对于部署目标为iOS 7的项目,Xcode将您的资产
    目录编译为运行时二进制文件格式,以减少应用程序的下载
    时间。

这就是它。

我也在寻找一种不使用 imageNamed:的方式,我不想要运行时缓存我的图像。

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

这篇关于访问资产目录pathForResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆