首页 > 其他分享 >SDWebImage的block使用

SDWebImage的block使用

时间:2022-12-09 15:06:57浏览次数:38  
标签:缓存 MYLog url image cachedImage block 使用 SDWebImage 图片

SDWebImageManager *sSDWebImageManager sharedManager];


UIImage *cachedImage = [sdManager imageWithUrl:url];// 将需要缓存的图片加载进来
//如果缓存中有图片
if (cachedImage) {
MYLog(@"有缓存图片");

[button setBackgroundImage:cachedImage forState:UIControlStateNormal];
}else
{
//如果缓存中没有图片,异步下载图片
MYLog(@"正在下载图片%@",url);
[sdManager downloadWithURL:url options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {

} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if (image) {
MYLog(@"下载完成的图片");
[button setBackgroundImage:image forState:UIControlStateNormal];
}
}];
}

标签:缓存,MYLog,url,image,cachedImage,block,使用,SDWebImage,图片
From: https://blog.51cto.com/u_15907570/5925300

相关文章

  • OC之【typedef的使用】
    //#defineIntegerint//给基本数据类型起别名voidtypedefinttypedefIntegertypedefunsignedintUInteger;inta=10;Integerb=9;......
  • OC之【NSMutableString的使用】
    可变字符串的创建void//预先分配10个字数的存储空间NSMutableString*str=[[NSMutableStringalloc]initWithCapacity:10];//设置字符串内容setString:@......
  • OC之【NSArray使用】
    #import<Foundation/Foundation.h>#import"Student.h"创建一个数组void//创建一个空的数组NSArray*array=[NSArrayarray];//创建有1个元素的数组NSAr......
  • OC之【NSMutableArray的使用】
    #import<Foundation/Foundation.h>#import"Student.h"voidNSMutableArray*array=[NSMutableArrayarrayWithObject:@"1"];//添加元素addObject:@"2"];addObj......
  • OC之【NSNumber的使用】
    #import<Foundation/Foundation.h>void//将int类型的10包装成一个NSNumber对象NSNumber*number=[NSNumbernumberWithInt:10];NSLog(@"number=%@",number);......
  • OC之【NSMutableDictionary的使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"可变字典的使用void//创建一个空的字典NSMutableDictionary*dict=[NSMutableDictionarydicti......
  • OC之【NSValue的使用】
    #import<Foundation/Foundation.h>voidCGPointpoint=CGPointMake(10,10);//将结构体变量包装成一个对象NSValue*value=[NSValuevalueWithPoint:point];......
  • OC之【NSDate使用】
    #import<Foundation/Foundation.h>日期创建void//date方法返回的就是当前时间(now)NSDate*date=[NSDatedate];//now:21:09:40//date:21:09:50......
  • OC之【NSObject使用】
    main.m文件#import<Foundation/Foundation.h>#import"Student.h"#import"Person.h"常用方法voidStudent*stu=[[[Studentalloc]init]autorelease];//isKin......
  • Java使用Steam流对数组进行排序
    原文地址:Java使用Steam流对数组进行排序-Stars-One的杂货小窝简单记下笔记,不是啥难的东西sorted()方法里传了一个比较器的接口Filefile=newFile("D:\\temp\\db_ba......