With AFNetworking, is very simple to download an image from a server and put into an UIImageView:
[imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
How about if I want to do this replacement of image with an effect (maybe fade)???
It's because I want to make a slideshow with a lot of images.
You can use
animateWithDuration
in conjunction with the rendition ofsetImageWithURL
that supplies thesuccess
block, e.g.Or, if you placeholder image isn't blank, you would probably want to cross dissolve via
transitionWithView
:Update:
By the way, if you're concerned about the fact that the image view (and if you refer to
self
, the view or the view controller, too) being retained until the download is done, you could:Even if you do that, the image view is retained until the download completes, so you could optionally also cancel any download in progress in the
dealloc
method of the view controller:Try animating the alpha of the imageView from 0 to 1 when the online request completes with success:
Of course you can use any other animation you like inside the completion block!