Using CGContext to draw line

后端 未结 2 1996
猫巷女王i
猫巷女王i 2021-01-12 06:02

I wanted to draw a line using CGContext and what I have so far is:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(con         


        
2条回答
  •  孤街浪徒
    2021-01-12 06:31

    These two lines are responsible for the start and end points:

    CGContextMoveToPoint(context, 10, 10);    // This sets up the start point
    CGContextAddLineToPoint(context, 100, 50); // This moves to the end point.
    

    By adjusting these two x, y points you can adjust the line. The length of the line depends on the start and end points.

    Following on from psoft's answer - here's a basic example project of drawing, including creating a path and stroking it.

    This is explained in more detail with more sample code in the Quartz 2D guide for paths.

提交回复
热议问题