Sunday, April 3, 2016

Displaying animated images/Gif in UIImageView


The easiest way to show animated image/gif on a UIImageView in iOS would be to give it the collection of images to animate, and call startAnimation

UIImageView* imgView = [[UIImageView alloc] init]; 
imgView.animationImages = [NSArray arrayWithObjects: 
[UIImage imageNamed:@"imgAtPosition1.gif"], 
[UIImage imageNamed:@"imgAtPosition2.gif"], 
[UIImage imageNamed:@"imgAtPosition3.gif"], 
[UIImage imageNamed:@"imgAtPosition4.gif"], 
.
.
., nil]; 
imgView.animationDuration = 0.4f; 
imgView.animationRepeatCount = 100; 
[imgView startAnimating]; 
[self.view addSubview: imgView];