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.9. Drawing Gradients

15.9. Drawing Gradients

Problem

You want to draw gradients on graphics contexts, using different colors.

Solution

Use the CGGradientCreateWithColor function.

Discussion

After learning about colors in Recipe 15.3, we’re ready to put the skills to better use than drawing simple rectangles and colorful text!

Core Graphics allows programmers to create two types of gradients: axial and radial. (We will only discuss axial gradients in this book.) Axial gradients are gradients that start from one point with one color and end at another point with another color (although they can start and stop with the same color, which does not make them much of a gradient). “Axial” means relating to an axis. The two points (start and end point) create a line segment, which will be the axis on which the gradient will be drawn. An example of an axial gradient is shown in Figure 15-26.


  

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