Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to show gif Images in iOS using FLAnimatedImageView

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.93k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: