forked from atomton/ATMHud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATMTextLayer.m
53 lines (42 loc) · 1.08 KB
/
ATMTextLayer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* ATMTextLayer.m
* ATMHud
*
* Created by Marcel Müller on 2011-03-01.
* Copyright (c) 2010-2011, Marcel Müller (atomcraft)
* All rights reserved.
*
* https://github.com/atomton/ATMHud
*/
#import "ATMTextLayer.h"
@implementation ATMTextLayer
@synthesize caption;
- (id)initWithLayer:(id)layer {
if ((self = [super init])) {
caption = @"";
}
return self;
}
+ (BOOL)needsDisplayForKey:(NSString *)key {
if ([key isEqualToString:@"caption"]) {
return YES;
} else {
return [super needsDisplayForKey:key];
}
}
- (void)drawInContext:(CGContextRef)ctx {
UIGraphicsPushContext(ctx);
CGRect f = self.bounds;
CGRect s = f;
s.origin.y -= 1;
[[UIColor blackColor] set];
[caption drawInRect:f withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
[[UIColor whiteColor] set];
[caption drawInRect:s withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
UIGraphicsPopContext();
}
- (void)dealloc {
[caption release];
[super dealloc];
}
@end