Search code examples
iosobjective-cuiimagexcasset

How to load all images with similar names


I have several images in my xcasset, so i can load image with:

[UIImage imageNamed:@"face_icon_1"];

If my images names is like "face_icon_2", "face_icon_3" and etc., how do i found them all and without hardcode?


Solution

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