我有一个我在UIView的drawRect方法中绘制的形状。
这是代码:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor brownColor] CGColor]);
CGContextAddArc(context, 50, 50, 50, 342.0 * (M_PI / 180), 90.0 * (M_PI / 180), 1);
CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextFillPath(context);
CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextStrokePath(context);
}
只有第一个功能(填充和描边之间)才有效。
如果我先敲击,则填充不起作用。
我该如何解决这个问题?
答案 0 :(得分:1)
为什么要设置两个FillColor? 你想要的是CGContextDrawPath()函数,而不是同时调用CGContextFillPath()和CGContextStrokePath。
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor brownColor] CGColor]);
CGContextAddArc(context, 50, 50, 50, 342.0 * (M_PI / 180), 90.0 * (M_PI / 180), 1);
// CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextDrawPath(context, kCGPathFillStroke);