我正在修改IOS应用程序以允许额外的背景层。所有现有的覆盖是UIImageViews
,处理transparency
就好了。使UIView前景透明
现有背景主要是UIView
。我想将黑色背景更改为transparent
,以表达另一种观点。它不起作用。它不工作,我会希望最简单的代码如下:
# import "TestUIView.h"
@implementation TestUIView
- (void)drawRect:(CGRect)rect {
self.opaque = NO;
[self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 0,0,0,0);
CGContextFillRect(context, rect);
// and here goes my code where I draw to the transparent background
}
@end
当这被执行,它会产生一个黑色的矩形。我已将其背景设置为透明,并以透明的方式填充其前景。我需要做些什么才能获得UIView
,我可以在透明背景下绘制?
(我知道我可以改变整个视图的alpha
,这不是问题,我希望在真正透明的背景上绘制不透明的图形)。
更新:它不在setbackgroundcolor中,我感谢它没有必要,所以不应该在那里,但同样的事情发生,如果它被注释掉。我不能背景透明;上面的代码显示我甚至无法制作透明矩形来绘制。
感谢
提供的只是尽量 yourview.backgroundColor = [[的UIColor blackColor ] colorWithComponent:0.5]; –
如果alpha为0,则不会看到任何内容。那么你期望什么?默认opaue为 –
。 –