ATMTextLayer.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * ATMTextLayer.m
  3. * ATMHud
  4. *
  5. * Created by Marcel Müller on 2011-03-01.
  6. * Copyright (c) 2010-2011, Marcel Müller (atomcraft)
  7. * All rights reserved.
  8. *
  9. * https://github.com/atomton/ATMHud
  10. */
  11. #import "ATMTextLayer.h"
  12. @implementation ATMTextLayer
  13. @synthesize caption;
  14. - (id)initWithLayer:(id)layer {
  15. if ((self = [super init])) {
  16. caption = @"";
  17. }
  18. return self;
  19. }
  20. + (BOOL)needsDisplayForKey:(NSString *)key {
  21. if ([key isEqualToString:@"caption"]) {
  22. return YES;
  23. } else {
  24. return [super needsDisplayForKey:key];
  25. }
  26. }
  27. - (void)drawInContext:(CGContextRef)ctx {
  28. UIGraphicsPushContext(ctx);
  29. CGRect f = self.bounds;
  30. CGRect s = f;
  31. s.origin.y -= 1;
  32. [[UIColor blackColor] set];
  33. // [caption drawInRect:f withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:NSTextAlignmentCenter];
  34. [caption drawInRect:f withAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14], NSForegroundColorAttributeName:[UIColor blackColor]}];
  35. [[UIColor whiteColor] set];
  36. // [caption drawInRect:s withFont:[UIFont boldSystemFontOfSize:14] lineBreakMode:UILineBreakModeWordWrap alignment:NSTextAlignmentCenter];
  37. [caption drawInRect:s withAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14], NSForegroundColorAttributeName:[UIColor whiteColor]}];
  38. UIGraphicsPopContext();
  39. }
  40. - (void)dealloc {
  41. // [caption release];
  42. // [super dealloc];
  43. }
  44. @end