Show activity indicator in SDWebImage

前端 未结 18 1426
独厮守ぢ
独厮守ぢ 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条回答
  •  猫巷女王i
    2021-01-30 09:42

    Best solution that worked for me is below. It is beautiful and encouraging to show progress indicator when image is downloading. I used UICircularSlider as rounded progress view. You can also try it.

        [_imgPost sd_setImageWithURL:urlPost placeholderImage:zeroImage options:SDWebImageContinueInBackground progress:^(NSInteger receivedSize, NSInteger expectedSize)
        {
            CGFloat domandeFloat = [[NSNumber numberWithInteger: receivedSize] floatValue];
            CGFloat corretteFloat = [[NSNumber numberWithInteger: expectedSize] floatValue];
    
    
            float currentProgress = (domandeFloat/corretteFloat)*100;
    
            NSLog(@"progress %.f%%",currentProgress);
            DBG(@"%li, %li", receivedSize, expectedSize);
            [_progress setValue:currentProgress];
        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    
            [_progress setHidden:YES];
        }];
    

    Here _progress is an instance of UICircularSlider

提交回复
热议问题