UIImageView+webImage.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // UIImageView+webImage.m
  3. // LampRibbon
  4. //
  5. // Created by coderYK on 2017/8/9.
  6. // Copyright © 2017年 RD-iOS. All rights reserved.
  7. //
  8. #import "UIImageView+webImage.h"
  9. @implementation UIImageView (webImage)
  10. - (void)rds_downloadImage:(NSString *)url placeHoler:(UIImage *)placeHoler {
  11. [self sd_setImageWithURL:[NSURL URLWithString:url]
  12. placeholderImage:placeHoler
  13. options:SDWebImageLowPriority | SDWebImageRetryFailed];
  14. }
  15. - (void)rds_downloadImage:(NSString *)url
  16. placeHoler:(UIImage *)placeHoler
  17. success:(rds_DownloadSuccessBlock)success
  18. failure:(rds_DownloadFailureBlock)failure
  19. received:(rds_DownloadProgressBlock)progress {
  20. [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeHoler options:SDWebImageRetryFailed | SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
  21. if (progress) {
  22. progress((float)receivedSize/expectedSize);
  23. }
  24. } completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  25. if (error && failure) {
  26. failure(error);
  27. }
  28. else if(success){
  29. self.image = image;
  30. success(cacheType, image);
  31. }
  32. }];
  33. }
  34. @end