Graphics Reference
In-Depth Information
next step is to set the layer's default properties and assign its position attribute to the
center of the button's background layer.
LISTING 11-4
LZButtonLayer -init
#import
“LZButtonLayer.h”
@implementation
LZButtonLayer
@synthesize
myColor;
- (
id
)init
{
if
(![
super
init
])
return nil
;
[
self
setCornerRadius
:10.0];
[
self
setBounds
:
CGRectMake
(0, 0, 100, 24)];
[
self
setBorderWidth
:1.0];
[
self
setBorderColor
:
kWhiteColor
];
textLayer
= [
CATextLayer layer
];
[
textLayer setForegroundColor
:
kWhiteColor
];
[
textLayer setFontSize
:20.0f];
[
textLayer setAlignmentMode
:
kCAAlignmentCenter
];
[
textLayer setString
:
@”blah”
];
CGRect
textRect;
textRect.
size
= [
textLayer preferredFrameSize
];
[
textLayer setBounds
:textRect];
[
textLayer setPosition
:
CGPointMake
(50, 12)];
[
self
addSublayer
:
textLayer
];
return self
;
}
The
-string
and
-setString:
methods (shown in Listing 11-5) retrieve and pass the
string
value into the underlying
CATextLayer
. This provides opaque access to the under-
lying
CATextLayer
as a convenience.
LISTING 11-5
LZButton -setString: and -string: Implementations
- (
NSString
*)string;
{
return
[
textLayer string
];
}