我想将一个UIView添加到我的UIViewController中,但在我决定在UIView内创建椭圆之前,我希望它是透明的。
在我创建椭圆之前,我可以将视图的alpha设置为0,但当我想添加椭圆时,背景色仍然是黑色。
这是一堆椭圆的样子:
在我的UIView中:
- (void)drawRect:(CGRect)rect
{
[self pushContext];
UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
[[UIColor redColor] setFill];
[oval fill];
self.opaque = NO;
[self setBackgroundColor:[UIColor clearColor]];
[oval addClip];
[self setBackgroundColor:[UIColor clearColor]];
[self popContext];
}
view.isOpaque = false
- spencer.smUIColor.clear
将是更好的选择,以便在整个代码中进行标准化。 - Cheok Yan Cheng