Can I access all images in a .xcassets at once?

心已入冬 提交于 2019-11-27 07:57:29

问题


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"].

What i'm looking for is something like:

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

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

Thanks!!


回答1:


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];

Hope it helps.



来源:https://stackoverflow.com/questions/24389720/can-i-access-all-images-in-a-xcassets-at-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!