小编Pet*_*ete的帖子

使用CGContext在一条线上绘制三角形/箭头

我正在使用route-me的框架来处理位置.在此代码中,两个标记(点)之间的路径将绘制为一条线.

我的问题:"如果我想在线条的中间(或顶部)添加箭头,我应该添加什么代码,以便它指向"

谢谢



- (void)drawInContext:(CGContextRef)theContext
{
    renderedScale = [contents metersPerPixel];

    float scale = 1.0f / [contents metersPerPixel];

    float scaledLineWidth = lineWidth;
    if(!scaleLineWidth) {
        scaledLineWidth *= renderedScale;
    }
    //NSLog(@"line width = %f, content scale = %f", scaledLineWidth, renderedScale);

    CGContextScaleCTM(theContext, scale, scale);

    CGContextBeginPath(theContext);
    CGContextAddPath(theContext, path);

    CGContextSetLineWidth(theContext, scaledLineWidth);
    CGContextSetStrokeColorWithColor(theContext, [lineColor CGColor]);
    CGContextSetFillColorWithColor(theContext, [fillColor CGColor]);

    // according to Apple's documentation, DrawPath closes the path if it's a filled style, so a call to ClosePath isn't necessary
    CGContextDrawPath(theContext, drawingMode);
}

Run Code Online (Sandbox Code Playgroud)

iphone core-graphics cgcontext quartz-2d

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

cgcontext ×1

core-graphics ×1

iphone ×1

quartz-2d ×1