Add animated Gif image in Iphone UIImageView

Velmurugan picture Velmurugan · Dec 8, 2010 · Viewed 134.5k times · Source

I need to load an animated Gif image from a URL in UIImageview.

When I used the normal code, the image didn't load.

Is there any other way to load animated Gif images?

Answer

Ishu picture Ishu · Dec 8, 2010
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