Iphone 在iOS上,如何用轮廓填充路径?(或同时填充和笔划路径)
在iOS上,如果我们这样做Iphone 在iOS上,如何用轮廓填充路径?(或同时填充和笔划路径),iphone,ios,ipad,core-graphics,Iphone,Ios,Ipad,Core Graphics,在iOS上,如果我们这样做 CGContextMoveToPoint(contextFoo, 0, 0); CGContextAddLineToPoint(contextFoo, x, y); CGContextAddLineToPoint(contextFoo, x2, y2); // ... and many more CGContextAddLineToPoint 然后在这之后,如果我们做一个CGContextStrokePath,我们会得到一个大纲,或者如果我们CGContextFil
CGContextMoveToPoint(contextFoo, 0, 0);
CGContextAddLineToPoint(contextFoo, x, y);
CGContextAddLineToPoint(contextFoo, x2, y2);
// ... and many more CGContextAddLineToPoint
然后在这之后,如果我们做一个CGContextStrokePath
,我们会得到一个大纲,或者如果我们CGContextFillPath
,我们会得到“填充”,但我们不能同时做这两件事,因为在一个笔划或填充之后,“当前路径”就消失了。我们怎样才能同时填充和绘制路径(比如想要黄色填充和橙色轮廓)
我们可以将MoveTo
和AddLine
调用移动到一个函数,然后调用该函数,进行填充,然后再次调用该函数,然后进行笔划,但是有许多x
和y
使得将它们全部传递到函数非常麻烦。有什么方法可以做到这一点
CGContextDrawPath(context, kCGPathFillStroke);
// to both Fill and Stroke your context
// or kCGPathFill/kCGPathStroke to only fill/stroke
顺便说一句,您可以使用以下方法保存路径(将其重新用于相同形状的多个对象):
CGPathBeginPath/MoveToPoint/AddLine/。。。非常类似于CGContext/
例如:
[[UIColor yellowColor] setFill];
[[UIColor orangeColor] setStroke];
CGContextDrawPath(context, kCGPathFillStroke);
顺便说一句,您可以使用以下方法保存路径(将其重新用于相同形状的多个对象):
CGPathBeginPath/MoveToPoint/AddLine/。。。非常类似于CGContext/
例如:
[[UIColor yellowColor] setFill];
[[UIColor orangeColor] setStroke];
CGContextDrawPath(context, kCGPathFillStroke);