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

后端 未结 1 1967
悲哀的现实
悲哀的现实 2020-12-11 20:48

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:@\"ima

相关标签:
1条回答
  • 2020-12-11 21:15

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

    enter image description here

    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.

    0 讨论(0)
提交回复
热议问题