ios - 如何为 gif 图像添加占位符图像?
问题描述
我有如下行代码,我可以知道如何在其中添加占位符图像吗?
#import "UIImage+animatedGIF.h"
_imgPromotion_Image.image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:_strPromotion_Image]];
请帮忙。谢谢你。
解决方案
添加以下 pod
pod 'SDWebImage', '~> 4.4.1'
pod 'SDWebImage/GIF'
现在导入
#import "FLAnimatedImage.h"
#import <SDWebImage/UIImageView+WebCache.h>
到您的 ViewController,然后尝试-
NSString *urlStr = @"https://staticimg.ngmm365.com/0dd3a526e657396c3dfba57799a2e5e4-w750_h336.gif";
FLAnimatedImageView *gifImageView = [[FLAnimatedImageView alloc] init];
gifImageView.contentMode = UIViewContentModeScaleAspectFit;
CGFloat y = (self.view.frame.size.height-self.view.frame.size.width)/2;
gifImageView.frame = CGRectMake(0, y, self.view.frame.size.width, self.view.frame.size.width);
[self.view addSubview:gifImageView];
[gifImageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
推荐阅读
- docker - 在 GitLab 中构建和注册后,Apline Docker Image 未找到 AWS
- macos - 有没有办法在 AppleScript 中获取文件的完整路径?
- python - 使用数组偏移量计算 numpy 中的增量
- java - HibernateProxy.toString 延迟初始化异常
- encryption - Neo4j 服务器证书不受信任
- javascript - 反应引导模式不显示
- python - 如何从不起作用的 pip 安装 mkvirtualenvwrapper?
- android - 如何为 android ndk 项目使用预构建的 c++ 库
- sql - 根据另一个表中的数据,使用来自不同行的数据将行插入到同一个表中
- typescript - 有没有办法为类的所有方法添加重试,而无需为每个方法手动添加代码?