1
我想用drawRect
來畫一個綠色圓圈,但我在綠色圓圈周圍的矩形區域中得到一個黑色背景。客觀C - 不需要的黑色背景在圓圈後面
我需要邊界矩形的填充是透明的。
這裏我DrawCircle
類:
- (void)drawRect:(CGRect)rect {
UIBezierPath *ballBezierPath = [UIBezierPath rect];
[[UIColor greenColor] setFill];
[ballBezierPath stroke];
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
}
我的研究表明,添加最後兩行設置opaque
和backgroundColor
會解決這個問題,但它仍然無法正常工作。
這裏就是我加入我的ViewController
的viewDidLoad
法副視點:
CGRect positionFrame = CGRectMake(160,160,200,200);
DrawCircle *drawBallView = [[DrawCircle alloc] initWithFrame:positionFrame];
[view1 addSubview:drawBallView];
有我錯過了一些東西還是有不同的方法,我可以走?