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

来源:互联网 发布:mac口红 编辑:程序博客网 时间:2024/04/27 18:25

一,工程图。

二,代码。

RootViewController.m

复制代码
#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"]];}
复制代码

 

原创粉丝点击