Common outline for two shapes drawn in drawRect: ObjectiveC

夙愿已清 提交于 2019-12-11 13:49:46

问题


I have two shapes in a UIView - one, an ellipse and two, a triangle drawn using UIBezierPath. I need to draw the outline of these two shapes combined. How can I do it?


回答1:


You can do an "outside" stroke (like stroke->outside in photoshop/pixelmator) by calling stroke to draw the outline and setting the inverse of your shapes as the clipping path first. To do the inverse of the clipping path see this answer: https://stackoverflow.com/a/10639523/461492 (read comments too).

So here are the steps:

  1. Set the full area as the clipping path.
  2. Call CGContextEOClip() for each of your shapes as described in the comments to the answer linked above.
  3. Stroke your shapes.

This might not be exactly what you want - it will draw the stroke as normal but the whole interior (the fill area) of your shapes will not be drawn. So whereas the thickness of the stroke would normally extend within the interior of your shapes, and the internal angles of your stroke would normally have the correct corners (rounded/mitered) - in this case it would be more like you stroked the shapes then deleted the fill-area, or did an "outside" stroke in an image editing program.



来源:https://stackoverflow.com/questions/16941042/common-outline-for-two-shapes-drawn-in-drawrect-objectivec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!