Guest User

Untitled

a guest
Jun 21st, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #define HORIZONTAL_MARGIN 1
  2.  
  3. #define PORTRAIT_SMALL 14
  4. #define PORTRAIT_LARGE 20
  5. #define LANDSCAPE_SMALL 10
  6. #define LANDSCAPE_LARGE 18
  7.  
  8. #import "BNTitleView.h"
  9.  
  10. @interface BNTitleView(Private)
  11. -(UILabel*)createLabelWithFontSize:(NSInteger)fontSize;
  12. -(void)adjustFontSize:(UIDeviceOrientation)orientation;
  13. @end
  14.  
  15. @implementation BNTitleView
  16.  
  17. @synthesize title, subTitle;
  18.  
  19. - (id)initWithFrame:(CGRect)frame {
  20. if ((self = [super initWithFrame:frame])) {
  21. title = [[self createLabelWithFontSize:PORTRAIT_LARGE] retain];
  22. subTitle = [[self createLabelWithFontSize:PORTRAIT_SMALL] retain];
  23. [self addSubview:title];
  24. [self addSubview:subTitle];
  25. self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  26. }
  27. return self;
  28. }
  29.  
  30.  
  31. - (void)layoutSubviews {
  32. CGFloat height = self.frame.size.height;
  33. CGFloat width = self.frame.size.width;
  34. [self adjustFontSize:[[UIDevice currentDevice] orientation]];
  35.  
  36.  
  37. CGFloat HEIGTH_FRACTION = (height / 5);
  38.  
  39. CGRect titleFrame = CGRectMake(0, HORIZONTAL_MARGIN, width, (HEIGTH_FRACTION * 3) - HORIZONTAL_MARGIN);
  40. [title setFrame:titleFrame];
  41.  
  42. CGRect subTitleFrame = CGRectMake(0, (HEIGTH_FRACTION * 3), width, (HEIGTH_FRACTION * 2) - HORIZONTAL_MARGIN);
  43. [subTitle setFrame:subTitleFrame];
  44.  
  45. }
  46.  
  47. -(UILabel*)createLabelWithFontSize:(NSInteger)fontSize {
  48.  
  49. UILabel *label = [[UILabel alloc] initWithFrame:self.bounds];
  50. label.backgroundColor = [UIColor clearColor];
  51. label.font = [UIFont boldSystemFontOfSize:fontSize];
  52. label.textColor = [UIColor whiteColor];
  53. label.shadowColor = [UIColor darkGrayColor];
  54. label.shadowOffset = CGSizeMake(0, -1);
  55. label.textAlignment = UITextAlignmentCenter;
  56.  
  57. return [label autorelease];
  58. }
  59.  
  60. -(void)adjustFontSize:(UIDeviceOrientation)orientation {
  61. if(orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft) {
  62. title.font = [UIFont boldSystemFontOfSize:LANDSCAPE_LARGE];
  63. subTitle.font = [UIFont boldSystemFontOfSize:LANDSCAPE_SMALL];
  64. } else {
  65. title.font = [UIFont boldSystemFontOfSize:PORTRAIT_LARGE];
  66. subTitle.font = [UIFont boldSystemFontOfSize:PORTRAIT_SMALL];
  67. }
  68. }
  69.  
  70. - (void)dealloc {
  71. [title release];
  72. [subTitle release];
  73. [super dealloc];
  74. }
  75.  
  76. @end
Add Comment
Please, Sign In to add comment