简体   繁体   中英

Draw a irregular polygon on iphone

i have this question: i have a array of points and i would draw a irregular polygon by this points with Quartz or similar. Can you suggest me the best way to make this?

MyTest drawRect is this:

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClearRect(ctx, rect);

    CGContextSetRGBStrokeColor(ctx, 255, 0, 255, 1);
    CGPoint points[6] = { CGPointMake(100, 200), CGPointMake(150, 250),
        CGPointMake(150, 250), CGPointMake(50, 250),
        CGPointMake(50, 250), CGPointMake(100, 200) };
    CGContextStrokeLineSegments(ctx, points, 6);
}

You can use UIBezierPath / NSBezierPath:

UIBezierPath *poly = [[UIBezierPath alloc] init];
[poly moveToPoint:CGPointMake(0.0, 0.0)];
[poly addLineToPoint:CGPointMake(1.0, 0.0)];
[poly addLineToPoint:CGPointMake(1.0, 1.0)];
[poly closePath];
[poly stroke]; // draw stroke
[poly release];

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