Show activity indicator in SDWebImage

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

    That's my solution. In that file : UIImageView+WebCache.m

    Find that method and change like that:

    - (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
    {
        UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
        [activity startAnimating];
        [activity setFrame:CGRectMake(self.frame.origin.x - 20, self.frame.origin.y - 10, self.frame.size.width, self.frame.size.height)];
        [self addSubview:activity];
    
        //[self setImageWithURL:url placeholderImage:placeholder options:0 progress:nil completed:nil];
    
        [self setImageWithURL:url
             placeholderImage:placeholder
                      options:0
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
         {
                 [activity removeFromSuperview];
         }];
    }
    

提交回复
热议问题