Last active
May 19, 2016 15:47
-
-
Save tsafrir/5627179 to your computer and use it in GitHub Desktop.
Use SDWebImage to download an image the display in UITableViewCell with fade in and the image cache build in SDWebImage. https://github.com/rs/SDWebImage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIImageView+WebCache.h" | |
// load the image in: | |
// - (void)configureCell:(MyCell*)cell atIndexPath:(NSIndexPath*)indexPath | |
// or in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
NSString *imageURLString = item.imageURL; | |
if (imageURLString) { | |
NSURL *url = [NSURL URLWithString:imageURLString]; | |
if (url) { | |
UIImage *placeholder = [UIImage imageNamed:@"image-shader"]; | |
__weak UIImageView *imageView = cell.largeImageView; | |
[cell.largeImageView setImageWithURL:url placeholderImage:placeholder options:SDWebImageRetryFailed | |
progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { | |
if (!error && image) { | |
imageView.image = image; | |
if (cacheType != SDImageCacheTypeMemory) { // fade in only on first download | |
imageView.alpha = 0.0; | |
[UIView animateWithDuration:0.30 animations:^{ | |
imageView.alpha = 1.0; | |
}]; | |
} | |
else { | |
imageView.alpha = 1.0; | |
} | |
} | |
}]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment