我有三个点,A、B、C,链接这三个点的代码如下
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
NSArray *points = @[ [NSValue valueWithCGPoint:CGPointMake(10.0f, 15.0f)],
[NSValue valueWithCGPoint:CGPointMake(100.0f, 170.0f)],
[NSValue valueWithCGPoint:CGPointMake(190.0f, 100.0f)],
];
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 2.0f);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineCap(context, kCGLineCapRound);
for(int i = 0;i<points.count; ++i){
NSValue *pointValue = [points objectAtIndex:i];
CGPoint point = [pointValue CGPointValue];
if ( i == 0) {
CGContextMoveToPoint(context, point.x, point.y);
} else {
CGContextAddLineToPoint(context, point.x, point.y);
}
}
CGContextStrokePath(context);
}
但是,两条线的交界处是一个角,我需要用圆绳连接B点。如下图:
怎么做?
最佳答案
您拥有的是 2 条直线,您要求的是(可能是 2 条直线,由它们连接)一条圆弧/贝塞尔曲线。
查看使用 CGPathAddArcToPoint
或 CGPathAddCurveToPoint
或 CGPathAddQuadCurveToPoint
。
关于ios - 如何加入圆角线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23267242/