【代码笔记】iOS-SDWebImage的使用

一,工程图。

【代码笔记】iOS-SDWebImage的使用

二,代码。

RootViewController.m

【代码笔记】iOS-SDWebImage的使用
#import "RootViewController.h"
//加入头文件
#import "UIImageView+WebCache.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title=@"SDWebImage使用";
    
    
    //要显示图片的view
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
    imageView.backgroundColor=[UIColor redColor];
    [self.view addSubview:imageView];
    
    
    //url为网上的图片地址
    NSString *url=@"http://f.dalang.gov.cn/uppic/2011-7-16/2011071610283352633.jpg";
    //当url不存在的时候,用本地的图片1.jpg来进行加载。
    [imageView setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"1.jpg"]];

}
【代码笔记】iOS-SDWebImage的使用