简体   繁体   中英

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:

在此输入图像描述

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

Can you suggest me ?

Thanks in advance.

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

You can do this also with UIKit (ie higher level API):

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

This will fill your path i current graphics context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM