Hardik Gajjar
Hardik Gajjar

Reputation: 5058

Asynchronous Image Loader with Activity Indicator in iOS

I want to do AsynchronousImage Loader with ActivityIndicator for download the Image from URL and set in UITableviewCell. I used the sdwebimage but instead of Placeholder image I want to set Activity Indicator so kinldy help me for this.

Upvotes: 0

Views: 1865

Answers (2)

ekinsol
ekinsol

Reputation: 531

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];
    [indicator setCenter:self.imageView.center];
    [self.contentView addSubview:indicator];

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

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

                       }];
}

Of course you could make a nice subclass for this

Upvotes: 1

Alex
Alex

Reputation: 653

Activity Indicator is a view and I suppose your placeholder image is only an image.

If sdwebimage doesn't give you the possibility adding view instead of placeholder image, the best way for you will be to use an animated image of an activity indicator.

Upvotes: 0

Related Questions