0

我有一个目录可以归结为:

/ 
 - character0 -- attribute0 -- image.png
 - character1 -- attribute0 -- image.png 

我把它放在 XCode 中,以便定义两个字符。现在我想加载每个 image.png

CIImage * cheetah = [CIImage imageWithContentsOfURL:[[NSBundle mainBundle] 
                     URLForResource:@"image" withExtension:@".png"]];

什么是猎豹?我怎样才能得到character0

4

1 回答 1

0

如果您只是将两个文件“image.png”添加到您的项目中,那么这两个文件都将被复制到应用程序包的顶级目录中,这样您的应用程序中就只有一个文件“image.png”。

如果将文件夹“character0”、“character1”拖到项目中并选择“为任何添加的文件夹创建文件夹引用”选项,则整个文件夹层次结构将被复制到应用程序包中,您可以分别引用资源例如

NSURL *url = [[NSBundle mainBundle] URLForResource:@"image"
                                     withExtension:@"png" 
                                      subdirectory:@"character0/attribute0"];
于 2013-04-06T10:23:34.220 回答