Created
October 28, 2014 15:32
-
-
Save palawer/9a0b9270d048459c8095 to your computer and use it in GitHub Desktop.
Get image from URL asynchronously with AFNetworking
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
- (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