gpt4 book ai didi

ios7 - 访问资源目录路径

转载 作者:行者123 更新时间:2023-12-03 05:36:01 25 4
gpt4 key购买 nike

看来:

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

对于 Images.xcassets Assets 目录内的 Assets ,不返回任何内容。我也尝试过:

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

[[NSBundle mainBundle] pathForResource:@"name"ofType:@"png"inDirectory:@"Images.xcassets"];

但是这些都不起作用。

有人成功检索目录中 Assets 的路径吗?

最佳答案

同样的问题,但我认为我们无法通过 pathForResource: 访问它,除了下面:

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

已经明确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.

我发现在编译的应用程序包中,出现了一个名为“Assets.car”的文件,我认为这是我项目中的整个图像集,并且应该被压缩或什么的.

引用Apple的文档:

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.

就是这样。

我也在寻找一种不使用 imageNamed: 的方法,我不希望运行时缓存我的图像。

关于ios7 - 访问资源目录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18968352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com