qiutangfengmian

方法一 使用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];

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2021-12-18
  • 2021-09-26
  • 2021-09-07
  • 2021-09-09
  • 2022-01-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案