Egi*_*gil 11 iphone core-graphics
我试图在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);
}
Run Code Online (Sandbox Code Playgroud)
如何让此代码显示透明背景?
通过该设置,只要您不设置为“否”,调用clearsContextBeforeDrawing
您的方法时背景就应该是透明的。drawRect:
删除 CGContextClearRect 和其他绘图调用。
归档时间: |
|
查看次数: |
5820 次 |
最近记录: |