我有这个问题: 我有一个点数组,我会用石英或类似的东西绘制一个不规则的多边形。 你能告诉我最好的方法吗?
MyTest drawRect是这样的:
- (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);
}
答案 0 :(得分:3)
您可以使用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];