【发布时间】:2011-01-26 19:45:43
【问题描述】:
我有一个带有图片的主视图。
我正在尝试使用[self.view addSubview:view2]; 添加一个子视图,但我希望 view2 背景是透明的。已尝试将 opaque=no 和背景颜色设置为 clearcolor,还尝试将 uiview 子类化并使用以下方法重写 drawrect:
#import "TransparentView.h"
@implementation TransparentView
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor clearColor]];
self.opaque=NO;
self.clearsContextBeforeDrawing=YES;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
}
@end
但仍然不显示子视图透明的背景......有什么想法吗?
【问题讨论】:
标签: iphone uiview transparent