码迷,mamicode.com
首页 > 移动开发 > 详细

加载GIF动画方法 iOS

时间:2016-08-16 13:13:25      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

方法一 使用UIWebView

_codeStr为gif网址      如果是本地的gif可以直接使用dataWithContentsOfFile方法

   NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_codeStr]];

   UIWebView  *codeWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,45, 45)];

   [codeWebView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

   [self.view addSubview:codeWebView];

该方法有一个弊端就是    gif图的大小不能改变,显示的就是它本来的大小。

方法二  通过SDWebImage方法 导入UIImage+GIF.h

    UIImageView *codeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,45, 45)];

    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_codeStr]];

    UIImage *image = [UIImage sd_animatedGIFWithData:data];//实现gif图的展示

    codeImageView.image = image;

    [self.view addSubview:codeImageView];

加载GIF动画方法 iOS

标签:

原文地址:http://www.cnblogs.com/qiutangfengmian/p/5775832.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!