加载一张gif动态图

不知道大家有没有碰到过加载一张gif图的问题 这里我整理了两个方法第一个是通过html  加载到一个Web上   另一个是通过SDWebImage来实现的  其实两个原理都是差不多的  使用第三方可能比较简单  但是大家可以可以自己写一下,话不多说上代码:


第一种方法:

  [super.navigationController setNavigationBarHidden:YES animated:TRUE];

    

    webView = [[UIWebView alloc]init];

    webView.frame = CGRectMake(00self.view.bounds.size.widthself.view.bounds.size.height);


    // 设定位置和大小

    NSString *html = [NSString stringWithFormat:@"<html><head><style>body{margin:0px;padding:0px}</style></head><body><img border=\"0\" src = \"searchwait.gif\" width=\"%f\"height=\"%f\" style=\"position: absolute; z-index: -1;margin:0px;padding:0px\"><body></head></html>",self.view.bounds.size.width,self.view.bounds.size.height];

    NSString *path = [[NSBundle mainBundlepathForResource:@"searchwait"ofType:@"gif"];

    NSURL *baseURL = [NSURL fileURLWithPath:path];

    [webView loadHTMLString:html baseURL:baseURL];

    webView.userInteractionEnabled = NO;

    webView.backgroundColor  = wc_white;

    webView.contentMode      = UIViewContentModeScaleAspectFill;

    webView.clipsToBounds    = YES;

    

    [self.view addSubview:webView];


第二种方法:

- (void)initLoadingImageView

{

    NSString  *name =@"loading.gif";

    NSString  *filePath = [[NSBundlebundleWithPath:[[NSBundlemainBundle] bundlePath]]pathForResource:name ofType:nil];

    NSData  *imageData = [NSDatadataWithContentsOfFile:filePath];

    

    if (!self.loadingImageView) {

        self.loadingImageView = [[UIImageView alloc]init];

    }

    //    imgView.image = [UIImage animatedImageWithAnimatedGIFData:imageData];

    self.loadingImageView.backgroundColor = [UIColor clearColor];

    self.loadingImageView.image = [UIImage sd_animatedGIFWithData:imageData];

    self.loadingImageView.frame = CGRectMake(0,0, 100,250/2.0);

    [self.view addSubview:self.loadingImageView];

    [self.view bringSubviewToFront:self.loadingImageView];

}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值