【问题标题】:How to add placeholder image for gif image?如何为 gif 图像添加占位符图像?
【发布时间】:2019-02-03 17:57:30
【问题描述】:

我有一个如下的行代码,我可以知道如何在其中添加占位符图像吗?

#import "UIImage+animatedGIF.h"

_imgPromotion_Image.image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL URLWithString:_strPromotion_Image]];

请帮忙。谢谢。

【问题讨论】:

  • 你可以先把你的占位符放到你的_imgPromotion_Image 。在后台异步下载 gif。下载完成后显示
  • @QuocNguyen 介意给我看一些示例代码吗?谢谢!
  • 对不起,只是建议。你应该先自己尝试一下
  • 我已经尝试过类似的方法,但它不起作用。 [_imgProductImage sd_setImageWithURL:[NSURL URLWithString:strProductImage] placeholderImage:[UIImage imageNamed:@"Placeholder.png"]];。 Gif 不会动画。

标签: ios objective-c uiimage animated-gif


【解决方案1】:

添加以下 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"]];

output result

【讨论】:

    猜你喜欢
    • 2017-05-08
    • 2013-04-24
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多