Add animated Gif image in Iphone UIImageView
This has found an accepted answered, but I recently came across the UIImage+animatedGIF UIImage extension. It provides the following category:
+[UIImage animatedImageWithAnimatedGIFURL:(NSURL *)url]
allowing you to simply:
#import "UIImage+animatedGIF.h"
UIImage* mygif = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:@"http://en.wikipedia.org/wiki/File:Rotating_earth_(large).gif"]];
Works like magic.
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"image1.gif"],
[UIImage imageNamed:@"image2.gif"],
[UIImage imageNamed:@"image3.gif"],
[UIImage imageNamed:@"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];
You can load more than one gif images.
You can split your gif using the following ImageMagick command:
convert +adjoin loading.gif out%d.gif
Here is the best solution to use Gif Image. Add SDWebImage from Github in your project.
#import "UIImage+GIF.h"
_imageViewAnimatedGif.image= [UIImage sd_animatedGIFNamed:@"thumbnail"];