Making UIView transparent

ios, screen, transparent, uiview

Solution

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        self.opaque = NO;

    }
    return self;
}



- (void)drawRect:(CGRect)rect
{
    [[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0] setFill];
    UIRectFill(rect);
    [self pushContext];
    UIBezierPath *oval = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
    [[UIColor redColor] setFill];
    [oval fill];

    [oval addClip];

    [self popContext];
}

Problem

I want to add a UIView to my UIViewController but I want it to be transparent until I decide to create an Oval inside the UIView. Until I create the oval, I can set my view's alpha to 0 but when I want to add the oval, the background color is still black. here's what it looks like with a bunch of ovals In my 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]; } ```

Original source