UIImageView * img = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[self.view addSubview:img];
NSURL *url = [NSURL URLWithString:@“”];
三种方法:
1、直接加载 (缓存地址)
[img sd_setImageWithURL:url];
2、两个过程。开始加载、加载完成
NSLog(@"开始加载");
[img sd_setImageWithURL:url completed:^(UIImage * image ,NSError * errpr, SDImageCacheType cacheType,NSURL * iamgeURL){
NSDate * senddate=[NSDate date];
NSLog(@"%@",senddate);
NSLog(@"加载完成");
}];
3、先加载本地图片,再加载网络图片
UIImage * image =[UIImage imageNamed:@"green.jpg"];
[img sd_setImageWithURL:url placeholderImage:image];
//获取缓存(全部图片)
int size = [[SDImageCache ShareImageCache]getSize];
//清除缓存(全部图片)
[[SDImageCache ShareImageCache]clearDisk]
时间: 2024-11-06 11:24:14