1. 首先, 需要将第三方的文件包导入到现在的工程中
2.在需要使用第三方图片的视图控制器的实现文件中导入文件:
#import "UIImageView+WebCache.h"
3.设置当前文件的TARGETS中第一项中的Build Phases中Compile Sources中将除了本文件中的都选中, 双击将这些文件Compiler Flages设置为: -fobjt-arc
4.创建一个UIImageView对象用来显示图片
5.设置属性: sd-setImageWithURL:()placeholderImage:()
参数说明: 1. 第三方图片的http地址
2.断网或者当前网络不能加载出图片时显示的本地图片 (苹果不允许出现空白页面)
代码如下:
#import "RootViewController.h"
#import "UIImageView+WebCache.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 400)];
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://img4.duitang.com/uploads/item/201207/28/20120728105310_jvAjW.thumb.600_0.jpeg"] placeholderImage:[UIImage imageNamed:@"1"]];
[self.view addSubview:imageView];
[imageView release];
}
运行结果: