Show activity indicator in SDWebImage

前端 未结 18 1378
独厮守ぢ
独厮守ぢ 2021-01-30 09:20

I\'m using SDWebView image and i want to show an Activity Indicator as placeholder, while fetching the image from remote.

I tried Malek\'s answer here How to show an act

18条回答
  •  礼貌的吻别
    2021-01-30 09:47

    The above code is slightly wrong. The line 'activityIndicator.center = imageView.center' does not give you the correct coordinates to center the progress view. For me, it was showing the indicator below the cell.

    Note - I am using the latest version of the SDWebImage code so the method is slightly different. I am also using a UIButton for the imageView

    Try this:

    NSURL *url = [NSURL URLWithString:@"www.someimageurl.com"];
    __block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator.frame = cell.imageView.bounds;
    [cell.imageView addSubview:activityIndicator];
    [activityIndicator startAnimating];
    [cell.imageView setImageWithURL:url forState:UIControlStateNormal completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
        [activityIndicator removeFromSuperview];
    }];
    

提交回复
热议问题