我想绘制一个带有一些圆圈的褪色黑色背景颜色的视图。它看起来应该是圆形部分应该是空心的,我应该能够看到下面的视图。
CALayer 掩蔽对我没有帮助,或者我可能没有以正确的方式应用它们(请参见下面的注释代码)。
下面是我的代码,附件是我现在看到的屏幕截图。
预期:带有空心圆圈的黑色褪色视图。
有什么建议么
#pragma Initializer
- (id)initWithFrame:(CGRect)iFrame andHollowFrames:(NSArray *)iHollowFrames {
if ((self = [super initWithFrame:iFrame]) != nil) {
self.hollowFrames = [NSArray arrayWithArray:iHollowFrames];
//self.layer.backgroundColor = CGColorCreateCopyWithAlpha([UIColor blackColor].CGColor, 0.5);
CAShapeLayer *circle1 = [self circleAt:CGPointMake(20.0, 20.0) ForRadius:10.0 withColor:[UIColor blackColor].CGColor andDashPattern:NO];
CAShapeLayer *circle2 = [self circleAt:CGPointMake(120.0, 20.0) ForRadius:10.0 withColor:[UIColor blackColor].CGColor andDashPattern:NO];
CALayer *myLayer = [CAShapeLayer layer];
myLayer.frame = self.frame;
myLayer.backgroundColor = CGColorCreateCopyWithAlpha([UIColor blackColor].CGColor, 0.5);
[self.layer addSublayer:myLayer];
// [circle1 setMask:myLayer];
// [circle2 setMask:myLayer];
[self.layer addSublayer:circle1];
[self.layer addSublayer:circle2];
}
return self;
}
#pragma Drawing Methods
- (CAShapeLayer *)circleAt:(CGPoint)iPoint ForRadius:(CGFloat)iRadius withColor:(CGColorRef)iColor andDashPattern:(BOOL)isDashPattern {
CAShapeLayer *aSignalcircle = [CAShapeLayer layer];
aSignalcircle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(iPoint.x, iPoint.y, 2.0 * iRadius, 2.0 * iRadius) cornerRadius:iRadius].CGPath;
aSignalcircle.position = CGPointMake(0.0 - iRadius, 0.0 - iRadius);
aSignalcircle.fillColor = [UIColor clearColor].CGColor;
aSignalcircle.strokeColor = iColor;
aSignalcircle.lineWidth = kPSSignalStrokeWidth;
aSignalcircle.backgroundColor = [UIColor clearColor].CGColor;
if (isDashPattern) {
aSignalcircle.lineDashPattern = @[@1, @1];
}
return aSignalcircle;
}