5 // Created by Jens Alfke on 3/10/08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "GGBTextLayer.h"
10 #import "QuartzUtils.h"
13 @implementation GGBTextLayer
16 + (GGBTextLayer*) textLayerInSuperlayer: (CALayer*)superlayer
17 withText: (NSString*)text
18 fontSize: (float) fontSize
19 alignment: (enum CAAutoresizingMask) align
21 GGBTextLayer *label = [[self alloc] init];
25 UIFont *font = [UIFont systemFontOfSize: fontSize];
27 NSFont *font = [NSFont systemFontOfSize: fontSize];
31 label.fontSize = fontSize;
32 label.foregroundColor = kBlackColor;
35 if( align & kCALayerWidthSizable )
37 else if( align & kCALayerMinXMargin )
41 align |= kCALayerWidthSizable;
42 label.alignmentMode = mode;
45 if( [superlayer respondsToSelector: @selector(borderWidth)] )
46 inset += ((GGBLayer*)superlayer).borderWidth;
47 CGRect bounds = CGRectInset(superlayer.bounds, inset, inset);
48 CGFloat height = font.ascender;
49 CGFloat y = bounds.origin.y;
50 if( align & kCALayerHeightSizable )
51 y += (bounds.size.height-height)/2.0;
52 else if( align & kCALayerMinYMargin )
53 y += bounds.size.height - height;
54 align &= ~kCALayerHeightSizable;
55 label.bounds = CGRectMake(0, font.descender,
56 bounds.size.width, height - font.descender);
57 label.position = CGPointMake(bounds.origin.x,y+font.descender);
58 label.anchorPoint = CGPointMake(0,0);
60 label.autoresizingMask = align;
61 [superlayer addSublayer: label];
68 @synthesize string=_string, fontSize=_fontSize,
69 foregroundColor=_foregroundColor, alignmentMode=_alignmentMode;