2014-08-30 57 views
0

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

[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

你是否将两个视图设置为'[UIColor clearColor]'?我认为你需要基于此:http://stackoverflow.com/questions/4633468/iphone-make-view-transparent-but-subviews-non-transparent – timpone 2014-08-30 21:09:54

+0

确定它现在的作品。我犯了一个愚蠢的错误。我有另一个功能,它控制了第一个视图的backgroundColor。 :( – Alan 2014-08-30 21:18:28

回答