how to draw line between two points?

前端 未结 6 565
难免孤独
难免孤独 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条回答
  •  萌比男神i
    2021-01-03 15:17

    Since this is 09' answers and whatnot I figure I update the link and code here for anyone looking in 11'.

    The link for the Quartz Demo is: http://developer.apple.com/library/ios/#samplecode/QuartzDemo/Introduction/Intro.html

    and the code I use to draw multiple lines is:

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

    I recommend reading Graphics and Animation on iOS: A Beginner's Guide to Core Graphics and Core Animation by Vandad Nahavandipoor. It's mostly on graphics than animation though. I recommend checking out his videos on animation if your interested. http://www.youtube.com/watch?v=ybMFPB-Gbsw&feature=player_embedded They're called Animations in iOS using Block Objects Part I and II. Supposedly there are supposed to be more videos at some point. But the videos go with the book.

    That's it.

提交回复
热议问题