使用UICollectionView加载图像。UICollectionView滚动时图像发生变化
以下是我的代码。 ImageArray将包含每个必须加载的图像的url。而在我的代码,我试着给一个圆形边框围绕整个的CollectionView
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
CALayer* layer = cell.layer;
[layer setCornerRadius:4.0f];
[layer setBorderColor:[UIColor colorWithWhite:0.8 alpha:1].CGColor];
[layer setBorderWidth:1.0f];
if ([ImageArray count] >0){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void) {
NSData *data0 = [NSData dataWithContentsOfURL: [NSURL URLWithString:[ImageArray objectAtIndex:indexPath.row]]];
UIImage *image = [UIImage imageWithData: data0];
dispatch_sync(dispatch_get_main_queue(), ^(void) {
recipeImageView.image = image;
});
});
}
[spinnerShow stopAnimating];
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
return cell;
}
的问题,即时通讯面临的是,
- 如果即时滚动它horizotally
- 内容被改变的图像圆形边框将呈现给collectionview的每个单元格,但圆形边框不会呈现给整个UICollectionView。
我该如何解决这个问题?
使用SDWebImage, https://github.com/rs/SDWebImage – itsji10dra
对于第二个问题,您将单元格的图层分配给'layer',这就是为什么边框不会呈现给整个UICollectionView。 – luiyezheng
我该如何将它展示给整个UICollectionView?谢谢 – Roger