私はそのようなパスを描くカスタム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の色は、白、赤、青の間でランダムにちらつきます。
それはなぜですか?
前もって感謝します!