我有一个UICollectionView。没有缓存,因为到目前为止我还没有需要应用,只有7个不同的图像,但可能有40个单元格。我对这种方法也没有经验。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIImageView *collectionImageView = (UIImageView *)[cell viewWithTag:102];
UILabel *ballLabel = (UILabel *)[cell viewWithTag:103];
UILabel *ballLabelInfo = (UILabel *)[cell viewWithTag:110];
ballShot *selectedBall = [self.statsView.visitBallShotCollection objectAtIndex:indexPath.row];
NSString *ballDetail;
NSString *labelInfo;
ballDetail = [NSString stringWithFormat:@"Foul"];
labelInfo = [NSString stringWithFormat:@"%@",[selectedBall getFoulTypeText:selectedBall.foulid]];
collectionImageView.image = [UIImage imageNamed:selectedBall.imageNameLarge];
ballLabel.text = ballDetail;
ballLabelInfo.text = labelInfo;
return cell;
}
我能够使用正确的内容大小保存UICollectionView的显示内容,但不能保存整个内容。
- (UIImage *) imageWithCollectionView:(UICollectionView *)collectionBreakView
{
CGSize widthHeight = CGSizeMake(collectionBreakView.contentSize.width, collectionBreakView.contentSize.height);
UIGraphicsBeginImageContextWithOptions(widthHeight, collectionBreakView.opaque, 0.0);
[collectionBreakView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
如何获取整个内容并放入UIImage?如果缓存是答案,有人可以给我一个启动设置吗? 提前谢谢。