Graphics Reference
In-Depth Information
LISTING 11-5
Continued
- (
void
)setString:(
NSString
*)string;
{
[
textLayer setString
:string];
CGRect
textRect;
textRect.
size
= [
textLayer preferredFrameSize
];
[
textLayer setBounds
:textRect];
}
The
-setSelected:
method (as shown in Listing 11-6) provides visible feedback to the
user so that they can see the click has an effect on the application. To show this effect, we
add and remove a Core Image filter (
CIBloom
) to the button layer depending upon the
BOOL
value being passed in.
LISTING 11-6
LZButton -setSelected: Implementation
- (
void
)setSelected:(
BOOL
)selected
{
if
(!selected) {
[
self
setFilters
:
nil
];
return
;
}
CIFilter
*effect = [
CIFilter filterWithName
:
@”CIBloom”
];
[effect
setDefaults
];
[effect
setValue
: [
NSNumber numberWithFloat
: 10.0f]
forKey
:
@”inputRadius”
];
[effect
setName
:
@”bloom”
];
[
self
setFilters
: [
NSArray arrayWithObject
:effect]];
}
NOTE
Remember that Core Image filters are currently only available on the desktop. Therefore, the
filter changes in the
-setSelected:
method will not work on a Cocoa Touch device.
With the
LZButton
layer designed, the next thing we build is the
AppDelegate
. The
AppDelegate
contains all the layers; add them to the window's
contentView
and receive
the delegate calls.
The only thing we do in Interface Builder is change the window's
contentView
to an
instance of
LZContentView
. After the class type has been changed, bind the
ContentView
's