我正在使用
绘制线条CGMutablePathRef path = CGPathCreateMutable();
for (int i = 0; i < [_points count]; i++)
{
CGPoint pt = [[_points objectAtIndex:i] CGPointValue];
if (i == 0)
{
CGPathMoveToPoint(path, NULL, pt.x+1, pt.y+1);
}
else
{
CGPathAddLineToPoint(path, NULL, pt.x+1, pt.y+1);
}
}
CGContextSetLineWidth(context, 1.0f);
CGContextSetStrokeColorWithColor(context, curveColor.CGColor);
CGContextAddPath(context, path);
CGContextStrokePath(context);
CGPathRelease(path);
我可以将线条向一个方向扩展。但我想在一定程度上向两个方向(上行和下行)延伸线。如何在两个方向延长线?
答案 0 :(得分:1)
扩展一端:
[_points insertObject:newStartPoint atIndex:0];
和另一个:
[_points addObject:newEndPoint];
答案 1 :(得分:0)
终于在@Wain评论的帮助下得到了答案,
- (NSArray *)lineDrawingPoints:(CGFloat)slope pointX1:(CGFloat)ptX1 pointY1:(CGFloat)ptY1 maxValX:(CGFloat)biggestNumberX maxValY:(CGFloat)biggestNumberY {
NSMutableArray *infiniteLinePoints = [NSMutableArray array];
float y;
for(int x = -biggestNumberX ; x <= biggestNumberX ; x++ ){
y = slope * (x - ptX1)+ptY1;
if(y >= -biggestNumberY && y <= biggestNumberY )
[infiniteLinePoints addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
}
return infiniteLinePoints;
}
谢谢Wain。