SDWebImage-ProgressView
在 UIImageView 上添加类别,在下载图像时添加进度视图(3.7.0 及以上版本)。
在 YouTube 上的示例
安装
使用 Cocoapods
pod 'SDWebImage-ProgressView'
使用
SDWebImage 的 UIView+WebCache 方法都增加了一个额外的参数
- (void)sd_setImageWithURL:(NSURL *)url usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView;
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock usingProgressView:(UIProgressView *)progressView;
对于 progressView
参数使用 nil
将使用系统默认的 UIProgressView
,或者如果您想自定义样式和色调颜色,提供您自己的进度视图(或其子类)。
如果您使用的是 sd_cancelCurrentImageLoad
方法,那么您还必须调用 removeProgressView
,否则您将会有持续时间过长的进度视图。
- (void)prepareForReuse {
[super prepareForReuse];
[self.imageView sd_cancelCurrentImageLoad];
[self.imageView removeProgressView];
}
鸣谢
本项目的想法来自于UIActivityIndicator-for-SDWebImage。衷心感谢Giacomo Saccardo的贡献。
许可协议
SDWebImage-ProgressView在MIT许可协议下可用。查看LICENSE文件获取更多信息。