我使用此功能作为功能的基础,使屏幕在圆形区域外变暗,并保持不变:
Mask a UIView with a cut-out circle
但我想做的是选择性地将圆圈着色为红色,但我的所有尝试都失败了。我哪里出错了?
[[self fillColor] set];
UIRectFill(rect);
CGContextRef context = UIGraphicsGetCurrentContext();
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect: self.circleFrame];
if (self.tintCircle)
{
float red[4] = {1,0,0,1};
CGContextSetFillColor(context, red);
[path fill];
}
else
{
[path fillWithBlendMode:kCGBlendModeDestinationOut alpha:1.0];
}
答案 0 :(得分:0)
最后很容易。我不得不剪掉圆圈,然后再用红色画出来。
- (void)drawRect:(CGRect)rect
{
[[self fillColor] set];
UIRectFill(rect);
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect: self.circleFrame];
[path fillWithBlendMode:kCGBlendModeDestinationOut alpha:1.0];
if (self.drawRedCircle)
{
[[UIColor redColor] setFill];
[path fillWithBlendMode:kCGBlendModeNormal alpha:0.5];
}
}