【代碼筆記】iOS-SDWebImage的使用,筆記ios-sdwebimage
一,工程圖。
二,代碼。
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"]];}