我无法绘制一些用颜色描边的线条,然后用另一个线条填充它们的内部(它们构成一个多边形)。
UIColor *houseBorderColor = [UIColor colorWithRed:(170/255.0) green:(138/255.0) blue:(99/255.0) alpha:1];
CGContextSetStrokeColorWithColor(context, houseBorderColor.CGColor);
CGContextSetLineWidth(context, 3);
// Draw the polygon
CGContextMoveToPoint(context, 20, viewHeight-19.5);
CGContextAddLineToPoint(context, 200, viewHeight-19.5); // base
CGContextAddLineToPoint(context, 300, viewHeight-119.5); // right border
CGContextAddLineToPoint(context, 120, viewHeight-119.5);
CGContextAddLineToPoint(context, 20, viewHeight-19.5);
// Fill it
CGContextSetRGBFillColor(context, (248/255.0), (222/255.0), (173/255.0), 1);
//CGContextFillPath(context);
// Stroke it
CGContextStrokePath(context);
CGContextStrokePath
注释掉后,我得到了这个结果:
但如果我取消注释CGContextStrokePath
并填写多边形,颜色会溢出笔画:
您如何获得这样的结果(无需重做整个绘图过程两次):