我试图在 CG 中获得透明背景,但它总是显示为黑色。
我有以下代码:
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
DLog(@">>> Alloc: DrawingCanvas [0x%X]", (unsigned int)self);
[self setOpaque:NO];
[self setBackgroundColor:[UIColor clearColor]];
}
return self;
}
- (void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect frame = rect;
int counter = 3;
CGContextClearRect(context, frame);
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, frame);
}
如何让此代码显示透明背景?
最佳答案
通过该设置,只要您不将 clearsContextBeforeDrawing
设置为 NO,当调用 drawRect:
方法时,背景就应该是透明的。删除 CGContextClearRect 和其他绘图调用。
关于iphone - CoreGraphics 中的透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5148084/