iOS 使用SDwebImage缓存图片并在断网时候显示

 [_loadImageViewsetShowActivityIndicatorView:YES];
    [_loadImageViewsetIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _loadImageView.contentMode = UIViewContentModeScaleAspectFill;
    [_loadImageViewsd_setImageWithURL:self.imageUrlplaceholderImage:nil];
    // 缓存图片
    SDWebImageManager *manager = [SDWebImageManagersharedManager];
    manager.delegate = self;
   
    [manager.imageDownloaderdownloadImageWithURL:self.imageUrloptions:SDWebImageDownloaderContinueInBackgroundprogress:^(NSInteger receivedSize, NSInteger expectedSize) {
       
    } completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
        NSLog(@"---save image is %@",image);
        [manager.imageCachestoreImage:image forKey:@"one"toDisk:YES];
    }];
 // 从缓存取图片并显示
SDWebImageManager *manager = [[SDWebImageManageralloc] init];
    UIImage *image = [manager.imageCacheimageFromMemoryCacheForKey:@"one"];

你可能感兴趣的:(iOS 使用SDwebImage缓存图片并在断网时候显示)