2014-08-27 53 views
0

我用这个作为特征的那昏暗的圆形区域外的屏幕,该屏幕将保持不变的基础:调色切出面具

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

这是最终很容易。我必须仍然切出圆圈,然后再次用红色绘制。

- (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]; 
    } 
}