how to draw line between two points?

前端 未结 6 581
难免孤独
难免孤独 2021-01-03 14:43

i want to draw line between two points in my view how it possible.?

Edit:ya thax.i have got solution. Line draw perfectly.I want to draw multiple line with different

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 15:23

    You need to use a few CoreGraphics functions:

    // 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);
    

    This example would draw a horizontal white line with a thickness of 2. Apple has some great sample code and tutorials including the QuartzDemo tutorial: http://developer.apple.com/iPhone/library/samplecode/QuartzDemo/index.html.

提交回复
热议问题