iOS中如何显示gif图

2023-04-25,

这篇文章主要介绍了iOS中如何显示gif图,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

显示本地gif图

SDWebImage和YYImage的显示本地图片代码。

//load loacle gif image- (void)loadLocaleGifImage{ //sdwebimage [self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"]; NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"gif"]; NSData *gifData = [NSData dataWithContentsOfFile:path]; UIImageView *sdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)]; sdImageView.image = [UIImage sd_animatedGIFWithData:gifData]; [self.view addSubview:sdImageView]; //yyImage show gif image [self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"]; YYImage *yyimage = [YYImage imageNamed:@"test.gif"]; YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage]; yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3); [self.view addSubview:yyImageView];}

加载网络的gif图

SDWebImage和YYImage的加载网络图片代码。

//download network gif image- (void)downloadNetworkGifImage{ //sdwebimage [self labelFactoryWithFrame:CGRectMake(0, 80, kScreenWidth, 20) title:@"SDWebImage"]; FLAnimatedImageView *sdImageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(0, 100, kScreenWidth, kScreenHeight/3)]; [sdImageView sd_setImageWithURL:[NSURL URLWithString:@"https://cache.yisu.com/upload/information/20201211/272/44763.gif"]]; [self.view addSubview:sdImageView]; //yyImage show gif image [self labelFactoryWithFrame:CGRectMake(0, kScreenHeight/2 - 20, kScreenWidth, 20) title:@"yyImage"]; YYImage *yyimage = [YYImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://cache.yisu.com/upload/information/20201211/272/44763.gif"]]]; YYAnimatedImageView *yyImageView = [[YYAnimatedImageView alloc] initWithImage:yyimage]; yyImageView.frame = CGRectMake(0, kScreenHeight/2, kScreenWidth, kScreenHeight/3); [self.view addSubview:yyImageView];}- (void)labelFactoryWithFrame:(CGRect)frame title:(NSString *)title{ UILabel *label = [[UILabel alloc] initWithFrame:frame]; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor blackColor]; label.font = [UIFont systemFontOfSize:14]; label.text = title; [self.view addSubview:label];}

Podfile文件内容

platform :ios, '10.0'inhibit_all_warnings!target 'GifDemo' dopod 'YYImage'pod 'SDWebImage/GIF'pod 'FLAnimatedImage'end

感谢你能够认真阅读完这篇文章,希望小编分享的“iOS中如何显示gif图”这篇文章对大家有帮助,同时也希望大家多多支持本站,关注本站行业资讯频道,更多相关知识等着你来学习!

《iOS中如何显示gif图.doc》

下载本文的Word格式文档,以方便收藏与打印。