Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

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

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!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...