1

我写了一个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);

}

4

1 回答 1

3

你在抚摸路径,而不是填充路径。您想设置上下文的笔触颜色,而不是填充颜色。使用CGContextSetRGBStrokeColor

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

作为参考,这里是 Apple 的关于描边和填充路径的文档。

于 2013-07-10T07:24:14.880 回答