我知道这个问题已经被问了很多次,但很明显有些不同。我正在一个UIImageView上绘制矩形框覆盖在人脸上,所以我需要矩形框是透明的。
据我所见,我正在遵循所有建议来在视图中绘制透明背景(例如清除当前图形上下文的矩形)。我还设置了视图不是不透明的,并将backgroundColor设置为clearColor。还需要其他步骤吗?
-(instancetype)init
{
self = [super init];
if ( self ) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.clearsContextBeforeDrawing = NO;
}
return self;
}
- (void)drawRect:(CGRect)rect {
UIBezierPath * path = [UIBezierPath bezierPathWithRect:rect];
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor clearColor] setFill];
CGContextClearRect(ctx, rect);
[self.rectColor setStroke];
path.lineWidth = 5.0;
[path stroke];
}
@end
我需要设置透明背景,但默认情况下此视图显示为黑色。我尝试直接清除CGContext的矩形,因为我听说这通常是解决方案。
drawRect
的UIView
。它们作为ImageView的子视图添加。它们绘制黄色bezier路径。 - Joey Carson