Ferdinand
Ferdinand

Reputation: 1193

How to draw filled polygons?

I would like to know how to draw filled polygons using CoreGraphics framework.

Here is example I am trying to draw:

enter image description here

I have A,B,C,D,E,F and G.

Can you suggest me ?

Thanks in advance.

Upvotes: 5

Views: 3833

Answers (2)

Aravindhan
Aravindhan

Reputation: 15628

- (void)drawRect:(CGRect)rect{      
    CGContextRef context= UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0);
    CGContextSetLineWidth(context, 1.0);
    CGContextMoveToPoint(context, 10, 50);
    CGContextAddLineToPoint(context, 100, 80);
    CGContextAddLineToPoint(context, 120, 120);
    CGContextAddLineToPoint(context, 60, 80);
    CGContextAddLineToPoint(context, 10, 50);
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    CGContextFillPath(context);
}

Upvotes: 4

debleek63
debleek63

Reputation: 1189

You can do this also with UIKit (i.e. higher level API):

UIBezierPath *path = [UIBezierPath ...];
...
[UIColor.redColor setFill];
[path fill];

This will fill your path i current graphics context.

Upvotes: 2

Related Questions