我正在使用代码绘制三角形,但如何在其中填充颜色。

    CGContextSetRGBStrokeColor(c, 255, 0, 255, 1);
//CGContextSetRGBStrokeColor(c, 1.0, 1.0, 1.0, 1.0);
// Drawing with a blue fill color
CGContextSetRGBFillColor(c, 0.0, 0.8, 1.0, 1.0);
CGPoint points[6] = { CGPointMake(142, 200), CGPointMake(150, 250),
CGPointMake(150, 250), CGPointMake(135, 250),
CGPointMake(135, 250), CGPointMake(142, 200) };
CGContextStrokeLineSegments(c, points, 6);

最佳答案

首先创建一个路径,然后填充它:

CGContextSetRGBFillColor(c, 0.0, 0.8, 1.0, 1.0);
CGPoint points[6] = { CGPointMake(142, 200), CGPointMake(150, 250),
    CGPointMake(150, 250), CGPointMake(135, 250),
    CGPointMake(135, 250), CGPointMake(142, 200) };
CGContextAddLines(c, points, 6);
CGContextClosePath(c);
CGContextFillPath(c);

10-06 13:10