UIBezierPath Simple Rectangle

I just want to draw a simple rectangle for presentation using the following function:

- (void)drawRect:(CGRect)rect { [super drawRect:rect]; if (self.drawTextBouble) { [[UIColor blueColor] setFill]; UIBezierPath *aPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(40, 0, 230, 120) cornerRadius:12.0]; [aPath fill]; } } 

The code above fills the view with a plain black background; outside the rectangle, it is not transparent. How can i fix this?

Edit:

The solution below works, but it also works:

 [self setOpaque:NO]; 
+7
source share
1 answer

You draw the code in order. If you want the custom pattern to be transparent, you just need to set

 self.backgroundColor = [UIColor clearColor]; 

in sight - (id)initWithFrame:(CGRect)frame

Edit: just a little note about calling [super drawRect:rect] . UIView docs says:

If your subclass is UIView directly, your implementation of this method does not require a call to super. However, if you subclass a different view class, you must call super at some point in your implementation.

+9
source

All Articles