iOS專案開發實戰——使用SDWebImage庫進行圖片請求

乞力馬紮羅的雪CYF發表於2015-09-22

     在實際的專案開發中,從網路上下載圖片是最基本的需求,最方便的做法就是使用SDWebImage來進行下載顯示。

(1)專案中匯入SDWebImage庫;

(2)程式碼實現如下:

#import "ViewController.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  
  NSURL *url = [[NSURL alloc] initWithString:@"http://www.fansimg.com/uploads2010/10/userid228895time20101022020424.jpg"];
  
  UIImageView *iv = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  
  [self.view addSubview:iv];
  
  [iv sd_setImageWithURL:url];
  
  
}

@end

(3)效果如下:

.


github主頁:https://github.com/chenyufeng1991  。歡迎大家訪問!


相關文章