如何在两点之间画线?

Man*_*nsi 2 iphone

我想在我看来两点之间画线如何可能.

编辑:你thax.i有解决方案.线条绘制完美.我想用不同的点绘制多条线.我正在使用for循环和每个旋转我通过起点和终点.但是只绘制了最后一点如何解决这个问题?

ric*_*and 6

您需要使用一些CoreGraphics函数:

// get the current context
CGContextRef context = UIGraphicsGetCurrentContext();

// set the stroke color and width
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetLineWidth(context, 2.0);

// move to your first point
CGContextMoveToPoint(context, 10.0, 10.0);

// add a line to your second point
CGContextAddLineToPoint(context, 50.0, 10.0);

// tell the context to draw the stroked line
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)

这个例子将绘制一条厚度为2的水平白线.Apple有一些很棒的示例代码和教程,包括QuartzDemo教程:http://developer.apple.com/iPhone/library/samplecode/QuartzDemo/index.html.