带轮廓的CGPath [英] CGPath with outline

查看:93
本文介绍了带轮廓的CGPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制带有笔触的CGPath。

I am trying to draw a CGPath that has a stroke for it's stroke.

基本上我想使用CGPath画一条线。然后,我想返回并在最后一个CGPath的两侧绘制线条,使其具有轮廓效果。

Basically I want a draw a line using CGPath. I then want to go back and draw lines on both sides of the last CGPath giving it the effect that it is outlines.

这条线可以以任何方式弯曲和旋转,但我总是需要外面的两条线跟随。

This line can bend and turn in any way but I always need the two lines on the outside to follow.

编辑:我需要使线的中间透明,但轮廓为纯黑色。

I need to be able to make the middle of the line transparent but the outlines solid black.

推荐答案

使用 CGPathCreateCopyByStrokingPath 抚摸旧路径来创建新路径在某些宽度。然后使用 kCGPathFillStroke 绘制新路径。

Use CGPathCreateCopyByStrokingPath to create a new path by stroking your old path at some width. Then draw your new path using kCGPathFillStroke.

- (void)drawRect:(CGRect)rect {
  CGContextRef context = UIGraphicsGetCurrentContext();

  CGMutablePathRef path = CGPathCreateMutable();
  CGPathMoveToPoint(path, NULL, 50, 50);
  CGPathAddLineToPoint(path, NULL, 200, 200);

  CGPathRef thickPath = CGPathCreateCopyByStrokingPath(path, NULL, 10, kCGLineCapButt, kCGLineJoinBevel, 0);
  CGContextAddPath(context, thickPath);

  CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
  CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
  CGContextSetLineWidth(context, 3);
  CGContextDrawPath(context, kCGPathFillStroke);

  CGPathRelease(thickPath);
  CGPathRelease(path);
}

这篇关于带轮廓的CGPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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