Graphics Reference
In-Depth Information
This pattern could get very complex if
we wanted it to. When you specify the
pattern you want to use, odd number
values are painted and even numbered
values are unpainted. For example, if
you specify the values 5, 10, 15, 20 ,
the stroke will show 5 units painted,
followed by 10 units unpainted,
followed by 15 units painted, followed
by 20 units unpainted. This pattern can
be specified with any interval you like.
Just remember: Odd equals painted and
even equals un-painted . The units defined
within the NSArray are expected to be
NSNumber objects and placing anything
else in that array can have unexpected
results.
Figure 10-2 shows the shape layer with
the stroke, as specified in Listing 10-2.
Note that one of the corners appears to
be missing because the gap in the line
pattern falls directly on that corner.
FIGURE 10-2
The Shape Layer with a Red-
Dashed Stroke
Using CAShapeLayer as a
Layer Mask
All CALayer -derived Core Animation layers have a property called mask . This property
enables you to mask everything in the layer except the portion where the layer mask has
content. For example, if you set the image layer's mask to a shape layer instead of adding
it to the layer tree, it allows only part of the image to show through where the shape
layer has been drawn. Listing 10-3 demonstrates the difference if we wanted to use a
shape layer as a mask instead of as a sublayer.
LISTING 10-3
Using CAShapeLayer as a Layer Mask
- ( void )viewDidLoad
{
[ super viewDidLoad ];
UIImage *balloon = [ UIImage imageNamed : @”balloon.jpg” ];
[[[ self view ] layer ] setContents :( id )[balloon CGImage]];
CGMutablePathRef path = CGPathCreateMutable ();
CGPathMoveToPoint (path, NULL , 0, 100);
Search WWH ::




Custom Search