I want use a gif in UIImageView, but I can't. My code is:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"gif"];
UIImage *testImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
self.dataImageView.animationImages = testImage.images;
self.dataImageView.animationDuration = testImage.duration;
self.dataImageView.animationRepeatCount = 1;
self.dataImageView.image = testImage.images.lastObject;
[self.dataImageView startAnimating];
}
Swift:
var url : NSURL = NSBundle.mainBundle().URLForResource("MAES", withExtension: "gif")
In objective C I had animatedImageWithAnimatedGIFData but in swift I don't know how call this or if not exists..
Thanks!
I assume you're using https://github.com/mayoff/uiimage-from-animated-gif for
+UIImage animatedImageWithAnimatedGIFData:
and the source code is in Objective-C.You'll need to first import your Objective-C headers into Swift. Using Swift with Cocoa and Objective-C explains how to do this:
You can then setup your
testImage
as follows: