1

How to display circular progress bar in uicollectionview with lazy loading image.

        ClothCell weakCell = (ClothCell )[collectionView dequeueReusableCellWithReuseIdentifier:@"ClothesCell" forIndexPath:indexPath];
        weakCell.tag=indexPath.item;
        weakCell.contentView.opaque = NO;
        weakCell.contentView.clipsToBounds = YES;
        weakCell.opaque = YES;
        weakCell.clipsToBounds = YES;
        weakCell.contentView.backgroundColor = [UIColor clearColor];
        Clothes *clothes = [self.arrayClothes objectAtIndex:indexPath.item];
        [weakCell.imageViewCloth setImage:nil];
          dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
     //   dispatch_async(dispatch_get_main_queue(), ^{
        [self.manager downloadWithURL:clothes.url options:SDWebImageLowPriority progress:^(NSUInteger receivedSize, long long expectedSize) {
            CGFloat domandeFloat = [[NSNumber numberWithInteger:receivedSize]floatValue];
            CGFloat corretteFloat = [[NSNumber numberWithLongLong:expectedSize] floatValue];
            float currentProgress = domandeFloat/corretteFloat;
                 [weakCell.circleProgressBar setProgress:currentProgress animated:YES];
        } completed:^(UIImage image, NSError error, SDImageCacheType cacheType, BOOL finished) {
            if(image){
                weakCell.imageViewCloth.image=image;
                weakCell.imageViewCloth.clipsToBounds = YES;
                weakCell.imageViewCloth.layer.borderWidth = 1.0;
                weakCell.imageViewCloth.layer.borderColor = [UIColor blackColor].CGColor;
                [weakCell.circleProgressBar setProgress:1 animated:YES];
            }
        }];

});
    //[weakCell.imageViewCloth setImageWithURL:clothes.url];

        return weakCell;
}

I have try this code and i face problem when i scroll up and down. It use same cell.

user4261201
  • 2,324
  • 19
  • 26
Ankit Kargathra
  • 309
  • 3
  • 16

1 Answers1

0

First of all, you should find a circular progress bar which you are going to use or build your own. I usually use one of these options:

  1. Use CALayer, draw progress using drawRect, animate progress using animatable variable using Facebook POP;
  2. Use CAShaperLayer and animate strokeEnd.

To make it work you should at least:

  1. Notify all visible cells that progress of your item which you download has changed and set new progress only to required cell;
  2. On - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath pre-populate progress.

This questions was already asked here, and here.

I made a little bit of research and found this one: XLRemoteImageView. Worth having a look. Thanks to xmartlabs.

Community
  • 1
  • 1
gontovnik
  • 690
  • 5
  • 9