首先導(dǎo)入頭文件
#import "UIImageView+WebCache.h"
1. sd_setImageWithURL:
[self.image1 sd_setImageWithURL:imagePath1];
2. sd_setImageWithURL:? completed:
//用block 可以在圖片加載完成之后做些事情
[self.image2 sd_setImageWithURL:imagePath2 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"這里可以在圖片加載完成之后做些事情");
}];
3. sd_setImageWithURL:? placeholderImage:
//給一張默認(rèn)圖片,先使用默認(rèn)圖片,當(dāng)圖片加載完成后再替換
[self.image1 sd_setImageWithURL:imagePath1 placeholderImage:[UIImage imageNamed:@"default"]];
4. sd_setImageWithURL:? placeholderImage:? completed:
//使用默認(rèn)圖片,而且用block 在完成后做一些事情
[self.image1 sd_setImageWithURL:imagePath1 placeholderImage:[UIImage imageNamed:@"default"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
NSLog(@"圖片加載完成后做的事情");
}];