user141302
user141302

Reputation:

how to fill through color in CGContextStrokeLineSegments?

i am using the code to draw a triangle , but how to fill color in it.

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

Upvotes: 3

Views: 2158

Answers (1)

Codo
Codo

Reputation: 78835

First create a path, then fill it:

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

Upvotes: 3

Related Questions