Skip to content

Instantly share code, notes, and snippets.

@palawer
Created October 28, 2014 15:32
Show Gist options
  • Save palawer/9a0b9270d048459c8095 to your computer and use it in GitHub Desktop.
Save palawer/9a0b9270d048459c8095 to your computer and use it in GitHub Desktop.
Get image from URL asynchronously with AFNetworking
- (UIImageView *)loadImageWithUrl:(NSString *)stringUrl
{
UIImageView *imageView = [[UIImageView alloc] init];
NSURL *url = [NSURL URLWithString:stringUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeholder = [UIImage imageNamed:@"placeholder"];
__weak UIImageView *weakImageView = imageView;
[imageView setImageWithURLRequest:request placeholderImage:placeholder success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[UIView transitionWithView:weakImageView duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
weakImageView.image = image;
} completion:nil];
} failure:nil];
return weakImageView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment