中风和填充不能一起工作 - 目标C.

时间:2013-07-19 11:50:59

标签: iphone ios objective-c ipad

我有一个我在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);
}

只有第一个功能(填充和描边之间)才有效。

如果我先敲击,则填充不起作用。

我该如何解决这个问题?

1 个答案:

答案 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);