We can easily display jpg images in the UIImageView. We can also display .gif images which supports animations so there is need to add some extra elements to our project. So for implementing this first install this podFile to your project :-
pod 'FLAnimatedImage', '~> 1.0'
After the installation of podFile, drag an UIImageView in the Main.Storyboard and then change the class of UIImage from UIImageView to FLAnimatedImageView in the Identity inspector. We can display images from the server url or by adding image which is saved locally into our project. Here both methods are provided.
Now include the following lines of code in the ViewController.m file :-
#import "FLAnimatedImage.h"
- (void)viewDidLoad {
[super viewDidLoad];
/* to show gif image from URL */
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://media1.giphy.com/media/l46CwQh6cojlkfLqg/200w_d.gif"]]];
_gifImageFromUrl.animatedImage = image;
/* to show GIF image from our project */
NSString * bundle = [[NSBundle mainBundle]pathForResource:@"flower" ofType:@"gif"];
NSLog(@"Bundle == %@== image ",bundle);
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfFile:bundle]];
_gifImageFromProject.animatedImage = image;
}
Build the project and the animated gifs will be displayed.
0 Comment(s)