Alan
Alan

Reputation: 40

Clear background-color on UIView with drawn content

Inside my FirstView, I put a second view which I wanted to use for drawn content. The drawing works fine, but the problem is that the background of that second view is black. I tried to set the background color of the view to clear color using:

[self setBackgroundColor:[UIColor clearColor]];

but it's still black.

#import "CustomView.h"

@interface CustomView ()

@end

@implementation CustomView


 -(void)drawRect:(CGRect)rect
    {

        UIBezierPath *aPath = [UIBezierPath bezierPath];

        aPath.lineWidth = 15;

        //set the stoke color
        [[UIColor greenColor] setStroke];

        // Set the starting point of the shape.
        [aPath moveToPoint:CGPointMake(100.0, 0.0)];

        // Draw the lines.
        [aPath addLineToPoint:CGPointMake(200.0, 40.0)];
        [aPath addLineToPoint:CGPointMake(160, 140)];
        [aPath addLineToPoint:CGPointMake(40.0, 140)];
        [aPath addLineToPoint:CGPointMake(0.0, 40.0)];
        [aPath closePath];

        //draw the path
        [aPath stroke];
    }





@end

Upvotes: 0

Views: 669

Answers (1)

timpone
timpone

Reputation: 19969

are you setting both views to [UIColor clearColor]? I think you need to based upon this: iphone: make view transparent but subviews non transparent

Upvotes: 3

Related Questions