ios - 如何加入圆角线

标签 ios cgcontext cgpath

我有三个点,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);   
}

enter image description here

但是,两条线的交界处是一个角,我需要用圆绳连接B点。如下图:

enter image description here

怎么做?

最佳答案

您拥有的是 2 条直线,您要求的是(可能是 2 条直线,由它们连接)一条圆弧/贝塞尔曲线。

查看使用 CGPathAddArcToPointCGPathAddCurveToPointCGPathAddQuadCurveToPoint

关于ios - 如何加入圆角线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23267242/

相关文章:

ios - 从在线 URL 播放视频有效,但从本地路径播放视频无效

ios - 如何将 plist 的数据包括字典行到字典数组以在代码上使用它

javascript - 如何使用 Objective-C 从 IOS Cordova 中的设备(本地数据库)中删除图像

IOS:CGRect 是对的,但 UIImage 翻转了

ios - 使用 iOS 设备从 HLS 视频流中截取屏幕截图

ios - 使用 CGContextDrawImage 旋转图像

objective-c - 为 iPhone 检测方 block 和方 block 游戏

ios - 使用 Cocoapods 构建静态库时防止重复符号

swift - 部分 UIView 的屏幕截图被屏蔽为 UIBezierPath/CGPath

ios - CGPathMoveToPoint 在创建路径时遇到一些麻烦