Home > Mobile >  How to load and animate images from Images.xcassets folder using UIImage array in objective c
How to load and animate images from Images.xcassets folder using UIImage array in objective c

Time:11-05

I have a folder in Images.xcassets which have 24 images. I want to add those images to the UIImage array and try to animate those images in a sequence. Is it possible to load the images from Images.xcassets into Array? Or is it better to use SVG images for animation?

To get single image I tried the following:

UIImage *image =  [UIImage imageNamed:@"FolderName"];

But I guess this needs to be modified as an Image array.

CodePudding user response:

I guess this might help you

UIImageView *imageView = [UIImageView.alloc initWithFrame:self.view.bounds];
    [self.view addSubview:imageView];
    
NSMutableArray *images = NSMutableArray.array;
NSInteger imageCount = 24;
NSString *imagePrefix = @"imageName_";
for(int i = 0; i<=imageCount; i  ){
    NSString *imageName = [NSString stringWithFormat:@"%@%d",imagePrefix, i];
    UIImage *image = [UIImage imageNamed:imageName];
    [images addObject:image];
}
imageView.animationImages = images;
imageView.animationRepeatCount = 1;
imageView.animationDuration = 3.0;
[imageView startAnimating];
  • Related