在xib中拖一个UIimageView控件
要导入第三方框架SDWebImage
#import "ViewController.h"
#import "UIImageView+WebCache.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
====================异步请求=======================
[_imageView setImageWithURL:[NSURL URLWithString:@"http://photo.candou.com/i/114/55b07f3725eae8b3cafc9bce10d16e46"]];
//图片还没加载出来时显示默认的图片
//[_imageView setImageWithURL:[NSURL URLWithString:@"http://photo.candou.com/i/114/2974e3a1afcf77d8574c47f2be5bcd9b"] placeholderImage:[UIImage imageNamed:@"美女01"]];
//====================系统自带的(属于同步请求)=======================
//通过接口去求图片资源
//NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://photo.candou.com/i/114/2974e3a1afcf77d8574c47f2be5bcd9b"]];
//把图片二进制流资源转成图片
//UIImage* image = [UIImage imageWithData:data];
//_imageView.image = image;
//===============================================================
NSLog(@"heheheheh");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end