【问题标题】:How to load all images with similar names如何加载具有相似名称的所有图像
【发布时间】:2015-09-03 18:50:09
【问题描述】:

我的 xcasset 中有几张图片,所以我可以加载图片:

[UIImage imageNamed:@"face_icon_1"];

如果我的图片名称类似于“face_icon_2”、“face_icon_3”等,我如何在没有硬编码的情况下找到它们?

【问题讨论】:

  • 您所说的“全部找到”是什么意思?您是否事先知道数字的范围,或者您想加载从 1 开始的图像,例如,直到最大可用数字?
  • 查找所有以“face_icon_”开头的图像,或者所有以“face_”开头的图像,这样我就会知道我的xcasset中有多少张图像

标签: ios objective-c uiimage xcasset


【解决方案1】:
UIImage *image;
NSInteger counter = 1;
do {
  image = [UIImage imageNamed:[NSString stringWithFormat:@"face_icon_%zd", counter++];
//add the image to an array
} while (image);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    相关资源
    最近更新 更多