Load image to UICollectionView Asynchronously?

后端 未结 3 2081
长情又很酷
长情又很酷 2020-12-29 15:46

How can i load images to a UICollectionview asynchronously? Inside following method?

- (PSTCollectionViewCell *)collectionView:(PSTCollectionVie         


        
3条回答
  •  情深已故
    2020-12-29 16:26

    Use Lazy Load File for your requirement.

    LazyLoad.h
    LazyLoad.m

    Use them like this

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    
        [cell addSubview:[self addViewWithURL:@"http://openwalls.com/image/399/explosion_of_colors_1920x1200.jpg" NFrame:CGRectMake(0, 0, 50, 50)]];
    
        cell.backgroundColor=[UIColor blueColor];
        return cell;
    }
    
    -(UIView*)addViewWithURL:(NSString*)urlStr NFrame:(CGRect)rect
    {
        LazyLoad *lazyLoading;
    
        lazyLoading = [[LazyLoad alloc] init];
        [lazyLoading setBackgroundColor:[UIColor grayColor]];
        [lazyLoading setFrame:rect];
    
        [lazyLoading loadImageFromURL:[NSURL URLWithString:urlStr]];
        return lazyLoading;
    }
    

    Download Demo Here

提交回复
热议问题