1

我想用以下方式画一个箭头:

- (void) drawArrowWithContext:(CGContextRef)context atPoint:(CGPoint)startPoint withSize: (CGSize)size lineWidth:(float)width arrowHeight:(float)aheight andColor:(UIColor *)color
{
float width_wing = (size.width-width)/2;
float main = size.height-aheight;

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextSetStrokeColorWithColor(context,[color CGColor]);

CGPoint rectangle_points[] =
{
    CGPointMake(startPoint.x + width_wing, startPoint.y + 0.0),
    CGPointMake(startPoint.x + width_wing, startPoint.y + main),
    CGPointMake(startPoint.x + 0.0, startPoint.y + main), // left point
    CGPointMake(startPoint.x + size.width/2, startPoint.y + size.height),

    CGPointMake(startPoint.x + size.width, startPoint.y + main), // right point

    CGPointMake(startPoint.x + size.width-width_wing, startPoint.y + main),

    CGPointMake(startPoint.x + size.width-width_wing, startPoint.y + 0.0),
    CGPointMake(startPoint.x + width_wing, startPoint.y + 0.0),
};

CGContextAddLines(context, rectangle_points, 8);

CGContextFillPath(context);
}

如您所见,我可以修复起始坐标 (CGPoint)startPoint,但我也想修复最终点。到目前为止,箭头始终指向下方。通过固定最后一点,我应该能够将它指向任何方向以及摆脱大小。我怎样才能在我的方法中插入这个?

4

0 回答 0