17.9. Adding Shadows to Shapes
You want to be able to apply shadows to shapes that you draw on graphic contexts.
It is easy to draw shadows using Core Graphics. The graphics context is the element that bears the shadow. What that means is that you need to apply the shadow to the context, draw the shapes that need the shadow, and then remove the shadow from the context (or set a new context). We will see an example of this soon.
In Core Graphics, we can use two procedures to apply a shadow to a graphics context:
This procedure, which creates black or gray shadows, accepts three parameters:
The graphics context on which the shadow has to be applied.
The offset, specified by a value of type
CGSize, from the right and the bottom part of each shape where the shadow has to be applied. The greater the x value of this offset is, the farther to the right of each shape the shadow will extend. The greater the y value of this offset is, the lower the shadow will extend.
The blur value that has to be applied to the shadow, specified as a floating-point value (
0.0fwill cause the shadow to be a solid shape. The higher this value goes, the more blurred the shadow will get. We will see an example of this soon.
This procedure accepts the exact same parameters as
CGContextSetShadow, with one addition. This fourth parameter, of type
CGColorRef, sets the color ...