Can I access all images in .xcassets at once?

I have a large number of images in Image.xcassets, and I need to load them all into a UITableView. But I do not want to write every name for [UIImage imageNamed:@"imageName"] .

What I'm looking for is something like:

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

Do you know if this is possible? If not, maybe I will create a .bundle ...

Thanks!!

+4
source share
1 answer

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

enter image description here

By adding a folder with the Create folder reference option, we will actually create a folder in the main set with its contents, and all your images will be divided. 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 this helps.

+7
source

Source: https://habr.com/ru/post/970839/


All Articles