user3051331 user3051331 - 1 year ago 100
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download