Reputation: 1749
I want to include gif files as a static resource in iOS app. I am using FLAnimatedImage library. I am able to load gif from the net and show using:
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://raphaelschaad.com/static/nyan.gif"]]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];
I have to load the GIF statically from local resources instead of fetching it from online. something like:
NSData dataWithContentsOfFile:LOCAL_FILEPATH
I am unable to add a gif to image assets but would like to include the image in local files. How do I do that?
PS: I am new to iOS development
Upvotes: 1
Views: 5949
Reputation: 82759
if you already known your path then you can call directly like
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = [UIImage animatedImageNamed:@"yourGifImageName" ]; // it take from assests
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];
else if you want to load from bundle
NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"youranimated.gif" ofType:nil]];
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:fileURL]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];
Upvotes: 4