所以,我有一个自定义单元格,我需要在tableView中将所有图像绘制为CGImage,但是我无法使其工作。我创建了一个测试项目并用简单的视图测试了代码。一切工作完美,当我复制相同的代码到我的自定义单元格时,它停止工作。这里是代码:在UITableView中绘制CGImage
-(void)drawRect:(CGRect)rect {
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
UIImage *karmaImage = [UIImage imageNamed:@"karma.png"];
[self drawImage:karmaImage withRect:CGRectMake(boundsX + 255, 16, 14, 14)];
}
-(void)drawImage:(UIImage *)image withRect:(CGRect)rect {
CGImageRef imageRef = CGImageRetain(image.CGImage);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, imageRef);
}
任何解决方案?
+1你不应该试图来覆盖'UITableViewCell'本身的图纸。你会打破各种事情。 –