我可以一次访问.xcassets中的所有图像吗? [英] Can I access all images in a .xcassets at once?

查看:146
本文介绍了我可以一次访问.xcassets中的所有图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Images.xcassets中有大量图像,我需要在UITableView中加载它们。但我不打算为 [UIImage imageNamed:@imageName] 写下每个名字。

I have a big amount of images in a Images.xcassets and I need to load them all in a UITableView. But I don't wat to write each name for the [UIImage imageNamed:@"imageName"].

我正在寻找的是:

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

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

Do you know if this is even possible? If not maybe i'll create a .bundle...

谢谢!!

推荐答案

Images.xcassets 复制捆绑中的所有图像,并与其他图像混合,更好地按照下图中的说明进行操作

Images.xcassets copies all the images in bundle, and it mixes up with other images, better follow the instructions in image below

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

By adding the folder with the option Create folder reference will actually create a folder in main bundle with its content, and all your images will be separated. And using the following code you can access all the images.

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

希望有所帮助。

这篇关于我可以一次访问.xcassets中的所有图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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