0

I used this as the basis of a feature that dims the screen outside a circle area which is left unaltered:

Mask a UIView with a cut-out circle

But what I would like to do is to optionally tint the circle red, but all my attempts have failed. Where am I going wrong please ?

[[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];
}
Community
  • 1
  • 1
Neil Coxhead
  • 575
  • 1
  • 4
  • 10

1 Answers1

0

It was quite easy in the end. I had to still cut out the circle and then draw it again in red.

- (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];
    }
}
Neil Coxhead
  • 575
  • 1
  • 4
  • 10