2014-08-30 102 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

回答