我有一个自定义的UIView,它可以像这样绘制路径
- (void)drawRect:(CGRect)rect{
[[UIColor blackColor] setStroke];
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColor(ctx, CGColorGetComponents(self.color));
CGContextFillPath(ctx);
UIBezierPath *thePath = [UIBezierPath bezierPath];
thePath.lineWidth = _lineWidth;
_center = CGPointMake(rect.size.width, rect.size.height);
[thePath moveToPoint:_center];
[thePath addArcWithCenter:_center radius:rect.size.width startAngle:M_PI endAngle:M_PI+degreesToRadians(_angle)clockwise:YES];
[thePath closePath];
[thePath fill];
}
我的自定义UIView还有一个方法可以更改填充颜色
- (void) changeColor:(UIColor *) newColor {
self.color = [newColor CGColor];
[self setNeedsDisplay];
}
如果我使用预定义颜色之一调用changeColor:方法,比如说:
[UIColor redColor]
一切正常。但如果我尝试给它自定义颜色,例如:
UIColor* color = [UIColor colorWithRed:1.0f green:0.0f blue:0.0f alpha:1.0f];
我的自定义UIView的颜色会随机闪烁在白色、红色和蓝色之间。
有什么想法是为什么会这样吗?
提前感谢您!