user3051331 user3051331 - 5 months ago 55
iOS Question

I want to show activity indicator before image loading in ios

I get the

image url
from webservice,i has loaded that image in
.Like as follows..

[ImageName setImageWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"image url"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]]].

It has taking time to load image in
. I want to display activity indicator before loading image in


You could do it this way :

Add an indicator to your view, place it at the center of your imageview

    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [indicator startAnimating];
    [self.contentView addSubview:indicator];

Remove the indicator from the superview in the block's succes method.

     NSUrl *anURL=[NSURL URLWithString:[[NSString stringWithFormat:@"image url"]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]];

    [_imageView setImageWithURL:[NSURL URLWithString:anURL]
                       success:^(UIImage *image) {
                           [indicator removeFromSuperview];
                       failure:^(NSError *error) {


Of course you could make a nice subclass for this