你的位置:首页 > 操作系统

[操作系统]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"];