如何在加载图像或其他资源时模拟我的Xcode项目中的目录/分组路径?

时间:2013-10-01 04:18:15

标签: iphone ios xcode

这就是我的Xcode项目的结构。

This is how my Xcode project is structured.

要访问bs-better@2x.png文件,我可以使用以下代码:

UIImage *cellIcon = [UIImage imageNamed:@"bs-better"];

这已经有效了。但是,为了便于阅读,我希望它能够在代码中包含分组路径,例如:

UIImage *cellIcon = [UIImage imageNamed:@"Assets/Icons/bs/bs-better"];

这可能吗?

2 个答案:

答案 0 :(得分:1)

是的,这是可能的,为此您需要创建物理目录而不是逻辑enter image description here

您必须添加“为任何添加的文件夹创建文件夹引用”的目录,而不是“为任何添加的文件夹创建组”,这样它将在下图中生成类似“示例目录”的物理目录,因此必须通过适当的方式访问路径。

enter image description here

答案 1 :(得分:0)

 UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bs-better" ofType:@"png"]];

这是从bundle获取文件的方法。