ios - 我可以一次访问 .xcassets 中的所有图像吗?

标签 ios objective-c xcasset

我在 Images.xcassets 中有大量图像,我需要将它们全部加载到 UITableView 中。但我不想为 [UIImage imageNamed:@"imageName"] 写下每个名称。

我正在寻找的是这样的东西:

NSArray *images = [MagicClass loadAllImagesIn:@"images.xcassets"];

你知道这是否可能吗?如果没有,也许我会创建一个 .bundle...

谢谢!!

最佳答案

Images.xcassets 将所有图像复制到 bundle 中,并将其与其他图像混合,最好按照下图中的说明进行操作

enter image description here

通过使用选项创建文件夹引用 添加文件夹,实际上会在主包中创建一个文件夹及其内容,并且您的所有图像都将被分开。使用以下代码,您可以访问所有图像。

NSString *dirPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"images"];
NSError * error;
NSArray * images =  [[NSFileManager defaultManager]
                      contentsOfDirectoryAtPath:dirPath error:&error];

希望对您有所帮助。

关于ios - 我可以一次访问 .xcassets 中的所有图像吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24389720/

相关文章:

ios - iOS分支深层链接无法在设备上打开应用程序,但在模拟器上效果很好

ios - 文本字段和警告

ios - 带有背景图像的 UItableviewcells 没有填满屏幕的整个宽度?

objective-c - NSTextField 自定义背景、边框和角

objective-c - NSBundle 的 -load 方法如何向 Objective-C 运行时注册类和其他运行时资源?

ios - 错误 Assets 目录编译器错误

ios - 如何以编程方式打开 App Store 应用程序的订阅页面?

iphone - 使用 XML 的最佳方式是什么?

ios - 加载图像不是从 .xcassets 文件夹?

ios - xcassets : A XXxXX app icon is required for iPhone apps targeting releases of iOS prior to 7. 0