Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

15. Graphics and Animations > 15.5. Drawing Lines

15.5. Drawing Lines

Problem

You simply want to be able to draw lines on a graphics context.

Solution

Retrieve the handle to your graphics context and then use the CGContextMoveToPoint and the CGContextAddLineToPoint functions to draw your line.

Discussion

When we talk about drawing shapes in iOS or OS X, we are implicitly talking about paths. What are paths, you may ask? A path is constructed from one or more series of points drawn on a screen. There is a big difference between paths and lines. A path can contain many lines, but a line cannot contain many paths. Think of paths as series of points—it’s as simple as that.

Lines have to be drawn using paths. Specify the start and end points, and then ask Core Graphics to fill that path for you. Core Graphics realizes that you have created a line on that path, and will paint that path for you using the color that you specified (see Recipe 15.3).


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial