我有一个非常简单的UIView子类,包含以下内容:
- (void)drawRect:(CGRect)rect{
CGContextRef context= UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetAlpha(context, 0.5);
CGContextFillEllipseInRect(context, CGRectMake(0,0,self.frame.size.width,self.frame.size.height));
}
但是当我将图像添加到UITableViewCell
的imageView时,图像的背景是黑色的。有什么办法可以把这个圆圈周围的背景弄清楚吗?
此外,我显示cell.imageView
的方法是向cell.imageView.image
添加一个较小的图像,因为没有它,imageView
就不会显示。有什么办法也能解决这个问题吗?
1.您应该设置
self.backgroundColor = [UIColor clearColor].
在您的初始化中。然后设置要填充的透明颜色。
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
最重要的步骤:
CGContextFillRect(context,self.bounds);
试试看。
在对上下文执行任何绘图操作之前,请执行以下操作:
CGContextClearRect(context, rect);