问题描述
我正在制作一个图像编辑器,可以创建不同形状的对象,如圆形,三角形和方形,也可以更新或删除。所以我使用 CAShapeLayer
来创建形状对象。
I am making an image editor which can create different shapes objects like circle, triangle and square which can also be updated or removed. So I have used CAShapeLayer
for creating shapes objects.
现在我还想在图像上画一条线也可以更新或删除所以我使用了bezierpath和 CAShapeLayer
创建该行,它工作正常。但现在的问题是,当我想选择任何现有的行时,可以选择任何接近行工具的地方,因为 CAShapeLayer
也设置了一条直线的填充区域从起点到终点。
Now I also want to draw a line on image which can also be updated or removed so I have used bezierpath and CAShapeLayer
to create the line, it is working fine. BUT now the problem is that when I want to select any existing line it can be selected any where close to line tool because CAShapeLayer
also set the fill region which will be a straight line from start point to end point.
我的问题是如何使用 CAShapeLayer
创建没有填充区域的行。
My question is that how can I create line with no fill region using CAShapeLayer
.
这是我创建行的代码:
CAShapeLayer *line = [CAShapeLayer layer];
// Using bezierpath to make line
UIBezierPath *linePath=[UIBezierPath bezierPath];
// Creating L with line
[linePath moveToPoint:point1];
[linePath addToPoint:point2];
[linePath addToPoint:point3];
line.path=linePath.CGPath;
// Configure the appearence of the line
line.fillColor = Nil;
line.opacity = 1.0;
line.strokeColor = [UIColor whiteColor].CGColor;
对此的任何想法都将非常感激。
Any idea on this will be really appreciated.
推荐答案
你能试试吗?它为我工作
Can you try this. Its work for me
CAShapeLayer *line = [CAShapeLayer layer];
UIBezierPath *linePath=[UIBezierPath bezierPath];
[linePath moveToPoint:CGPointMake(startx, starty)];
[linePath addLineToPoint:CGPointMake(endx, endy)];
line.lineWidth = 10.0;
line.path=linePath.CGPath;
line.fillColor = shapecolor.CGColor;
line.strokeColor = shapecolor.CGColor;
[[self.view layer] addSublayer:line];
这篇关于使用CAShapeLayer对象使用Bezierpath绘制线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!