Show activity indicator in SDWebImage

前端 未结 18 1580
独厮守ぢ
独厮守ぢ 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:58

    This fork has support for this functionality. Take a look at the diff.

    But, in general, you can do it rather easily without using that fork:

    __block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:activityStyle];
    activityIndicator.center = imageView.center;
    activityIndicator.hidesWhenStopped = YES;
    [imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]
                            success:^(UIImage *image) { [activityIndicator removeFromSuperview]; }
                            failure:^(NSError *error) { [activityIndicator removeFromSuperview]; }];
    
    [imageView addSubview:activityIndicator];
    [activityIndicator startAnimating];
    

提交回复
热议问题