在UIView上用绘制的内容清除背景颜色

时间:2014-08-30 20:58:04

标签: ios objective-c uiview uicolor

在我的FirstView中,我放了第二个视图,我想用它来绘制内容。绘图工作正常,但问题是第二个视图的背景是黑色的。我尝试使用以下方法设置视图的背景颜色以清除颜色:

[self setBackgroundColor:[UIColor clearColor]];

但它仍然是黑色的。

#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

1 个答案:

答案 0 :(得分:2)

您是否将两个视图都设置为[UIColor clearColor]?我认为您需要基于此:iphone: make view transparent but subviews non transparent