安装第三方库
pod 'FLAnimatedImage'
引入头文件 FLAnimatedImage
#import "FLAnimatedImageView+WebCache.h"
新建一个FLAnimatedImageView文章来源:https://www.toymoban.com/news/detail-553513.html
@property (strong, strong) FLAnimatedImageView *music_play_view;
创建gif视图,可以使用本地文件或者url展示文章来源地址https://www.toymoban.com/news/detail-553513.html
_music_play_view = [FLAnimatedImageView new];
[self addSubview:_music_play_view];
[_music_play_view mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self);
make.left.mas_equalTo(19);
make.width.mas_equalTo(20);
make.height.mas_equalTo(20);
}];
//文件在本地
NSData *localData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"PlayMusic.gif" ofType:nil]];
//文件时URL
//NSData *localData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"https://xxx.xxx.xxx/media/active_page/1ffN9fa1_20190720092942_301.gif"]];
FLAnimatedImage *animatedImage = [FLAnimatedImage animatedImageWithGIFData:localData];
_music_play_view.animatedImage = animatedImage;
到了这里,关于iOS学习-使用FLAnimatedImage加载Gif的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!