在drawRect中绘制的两个形状的通用轮廓:ObjectiveC [英] Common outline for two shapes drawn in drawRect: ObjectiveC

查看:80
本文介绍了在drawRect中绘制的两个形状的通用轮廓:ObjectiveC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIView 中有两个形状-一个是椭圆,另外两个是 UIBezierPath 绘制的>三角形。我需要将这两个形状的轮廓组合起来。我该怎么办?

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?

推荐答案

您可以执行外部笔画(例如在Photoshop / pixelmator中笔画->外部)通过调用描边绘制轮廓并将形状的逆设置为剪切路径。要进行剪切路径的逆运算,请参见以下答案: https://stackoverflow.com/a/10639523/461492

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).

所以这是步骤:


  1. 设置

  2. 为每个形状调用 CGContextEOClip(),如上面链接的答案的注释中所述

  3. 描边形状。

  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.

这篇关于在drawRect中绘制的两个形状的通用轮廓:ObjectiveC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆