iOS SDWebImage 加载网络 gif

在SDWebImage 4.4.0 版本之前想要通过url加载展示gif效果, 只需要用 UIImageView 创建的对象调用下面的方法就能实现:

#import <SDWebImage/UIImageView+WebCache.h>

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;

但在 4.4.0 版本之后换了另外一种方式, 新增加了 FLAnimatedImageView 来实现动态图片的展示,继承自 UIImageView ,首先要 pod 引入下面的框架:

pod 'SDWebImage/GIF'
然后使用 FLAnimatedImageView 来替换之前的 UIImageView 创建的对象, 再用该对象调用 sd_setImageWithURL: 方法即可:

#import <SDWebImage/FLAnimatedImageView+WebCache.h>

FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];

NSURL *url = [NSURL URLWithString:(NSString *)object.strIcon];
[imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"icon_placeholder"]];
--------------------- 
 

猜你喜欢

转载自blog.csdn.net/georgehenrywilliam/article/details/89147092