如何为 gif 图片添加占位符图片?
How to add placeholder image for gif image?
我有一行代码如下,我可以知道如何在其中添加占位符图像吗?
#import "UIImage+animatedGIF.h"
_imgPromotion_Image.image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:_strPromotion_Image]];
请帮忙。谢谢。
添加关注pods
pod 'SDWebImage', '~> 4.4.1'
豆荚'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"]];
output result
我有一行代码如下,我可以知道如何在其中添加占位符图像吗?
#import "UIImage+animatedGIF.h"
_imgPromotion_Image.image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:_strPromotion_Image]];
请帮忙。谢谢。
添加关注pods
pod 'SDWebImage', '~> 4.4.1'
豆荚'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"]];
output result