Drawing simple lines on iPhone with CoreGraphics

后端 未结 5 2531
后悔当初
后悔当初 2021-02-20 18:09

I would like to draw a straight line between where a user touches the screen, and where the touch ends. i need multiple lines, for if the user repeats the touch-drag-release act

5条回答
  •  广开言路
    2021-02-20 18:47

    The complete code is as below.

    /* Set the color that we want to use to draw the line */ 
    [[UIColor brownColor] set];
    /* Get the current graphics context */ 
    CGContextRef currentContext =UIGraphicsGetCurrentContext();
    /* Set the width for the line */
    CGContextSetLineWidth(currentContext,5.0f);
    /* Start the line at this point */ 
    CGContextMoveToPoint(currentContext,50.0f, 10.0f);
    /* And end it at this point */ 
    CGContextAddLineToPoint(currentContext,100.0f, 200.0f);
    /* Use the context's current color to draw the line */
    CGContextStrokePath(currentContext);
    

提交回复
热议问题