iOS CGContextSetRGBFillColor无法正常工作,颜色始终为黑色

时间:2013-07-10 07:17:19

标签: ios

我编写了一个CALayer的子类,并重写了该方法: - (void)drawInContext:(CGContextRef)ctx。但是CGContextSetRGBFillColor无法正常工作。帮助,帮助!

- (void)drawInContext:(CGContextRef)ctx
{
    //CGContextSaveGState(ctx);
    for (int i = 0; i < pointArray.count-1; i++)
    {
        HQPoint *point = [pointArray objectAtIndex:i];
        HQPoint *pointNext = [pointArray objectAtIndex:i+1];
        CGContextMoveToPoint(ctx, point.piontX, point.piontY);
        CGContextAddLineToPoint(ctx, pointNext.piontX, pointNext.piontY);
    }
     CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
     CGContextSetLineWidth(ctx, 1);

    CGContextStrokePath(ctx);
    //CGContextRestoreGState(ctx);

}

1 个答案:

答案 0 :(得分:3)

你正在抚摸这条路,而不是填补它。您想要设置上下文的笔触颜色,而不是填充颜色。使用CGContextSetRGBStrokeColor

 CGContextSetRGBStrokeColor(ctx, 1, 0, 0, 1);

供参考,这是Apple关于stroking and filling paths的文档。