Graphics Reference
In-Depth Information
LISTING 10-3
Continued
CGPathAddLineToPoint
(path,
NULL
, 200, 0);
CGPathAddLineToPoint
(path,
NULL
, 200, 200);
CGPathAddLineToPoint
(path,
NULL
, 0, 100);
shapeLayer = [[
CAShapeLayer alloc
]
init
];
[shapeLayer
setBounds
:
CGRectMake
(0, 0, 200, 200)];
[shapeLayer
setFillColor
:[[
UIColor purpleColor
]
CGColor
]];
[shapeLayer
setPosition
:
CGPointMake
(200, 200)];
[shapeLayer
setPath
:path];
[[[
self
view
]
layer
]
setMask
:shapeLayer];
}
The initialization code for the layer is identical to the code in Listing 10-1. The difference
in Listing 10-3 is that we have changed the method call from
-addSublayer
to
-setMask
,
passing it the
CAShapeLayer
. Figure 10-3 shows what the view looks like after applying
this change.
FIGURE 10-3
Using a Layer Mask to Create a Triangle Filled with the Image