我正在尝试绘制各有不同颜色的线条。 (但已连接)如果我不添加第二行并对其进行描边,则颜色为红色,但是当我添加第二行时,整个内容为黄色。如何使两条线显示不同的颜色?我的代码如下。
CGPoint FirstCGPoint = [self pointForMapPoint:cr.points[0]];
CGPathMoveToPoint(path, NULL, FirstCGPoint.x, FirstCGPoint.y);
CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
CGPoint SecondCGPoint = [self pointForMapPoint:cr.points[1]];
CGPathAddLineToPoint(path, NULL, SecondCGPoint.x, SecondCGPoint.y);
CGContextAddPath(context, path);
CGContextStrokePath(context);
CGContextSetStrokeColorWithColor(context, [[UIColor yellowColor] CGColor]);
CGPoint NewFirstCGPoint = [self pointForMapPoint:cr.points[3]];
CGPathAddLineToPoint(path, NULL, NewFirstCGPoint.x, NewFirstCGPoint.y);
CGContextAddPath(context, path);
CGContextStrokePath(context);
最佳答案
试试吧,您不需要使用路径。
CGPoint FirstCGPoint = CGPointMake(10.0f, 40.0f) ;
CGContextMoveToPoint(context, FirstCGPoint.x, FirstCGPoint.y) ;
CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
CGPoint SecondCGPoint = CGPointMake(10.0f, 100.0f) ;
CGContextAddLineToPoint(context, SecondCGPoint.x, SecondCGPoint.y);
CGContextStrokePath(context);
CGContextSetStrokeColorWithColor(context, [[UIColor yellowColor] CGColor]);
CGPoint NewFirstCGPoint = CGPointMake(100.0f, 100.0f) ;
CGContextMoveToPoint(context, SecondCGPoint.x, SecondCGPoint.y) ;
CGContextAddLineToPoint(context, NewFirstCGPoint.x, NewFirstCGPoint.y) ;
CGContextStrokePath(context);
关于ios - CGContextStrokePath使用线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20794729/