Created
November 10, 2010 21:29
-
-
Save bonkowski/671552 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define HORIZONTAL_MARGIN 1 | |
#define PORTRAIT_SMALL 14 | |
#define PORTRAIT_LARGE 20 | |
#define LANDSCAPE_SMALL 10 | |
#define LANDSCAPE_LARGE 18 | |
#import "BNTitleView.h" | |
@interface BNTitleView(Private) | |
-(UILabel*)createLabelWithFontSize:(NSInteger)fontSize; | |
-(void)adjustFontSize:(UIDeviceOrientation)orientation; | |
@end | |
@implementation BNTitleView | |
@synthesize title, subTitle; | |
- (id)initWithFrame:(CGRect)frame { | |
if ((self = [super initWithFrame:frame])) { | |
title = [[self createLabelWithFontSize:PORTRAIT_LARGE] retain]; | |
subTitle = [[self createLabelWithFontSize:PORTRAIT_SMALL] retain]; | |
[self addSubview:title]; | |
[self addSubview:subTitle]; | |
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
} | |
return self; | |
} | |
- (void)layoutSubviews { | |
CGFloat height = self.frame.size.height; | |
CGFloat width = self.frame.size.width; | |
[self adjustFontSize:[[UIDevice currentDevice] orientation]]; | |
CGFloat HEIGTH_FRACTION = (height / 5); | |
CGRect titleFrame = CGRectMake(0, HORIZONTAL_MARGIN, width, (HEIGTH_FRACTION * 3) - HORIZONTAL_MARGIN); | |
[title setFrame:titleFrame]; | |
CGRect subTitleFrame = CGRectMake(0, (HEIGTH_FRACTION * 3), width, (HEIGTH_FRACTION * 2) - HORIZONTAL_MARGIN); | |
[subTitle setFrame:subTitleFrame]; | |
} | |
-(UILabel*)createLabelWithFontSize:(NSInteger)fontSize { | |
UILabel *label = [[UILabel alloc] initWithFrame:self.bounds]; | |
label.backgroundColor = [UIColor clearColor]; | |
label.font = [UIFont boldSystemFontOfSize:fontSize]; | |
label.textColor = [UIColor whiteColor]; | |
label.shadowColor = [UIColor darkGrayColor]; | |
label.shadowOffset = CGSizeMake(0, -1); | |
label.textAlignment = UITextAlignmentCenter; | |
return [label autorelease]; | |
} | |
-(void)adjustFontSize:(UIDeviceOrientation)orientation { | |
if(orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft) { | |
title.font = [UIFont boldSystemFontOfSize:LANDSCAPE_LARGE]; | |
subTitle.font = [UIFont boldSystemFontOfSize:LANDSCAPE_SMALL]; | |
} else { | |
title.font = [UIFont boldSystemFontOfSize:PORTRAIT_LARGE]; | |
subTitle.font = [UIFont boldSystemFontOfSize:PORTRAIT_SMALL]; | |
} | |
} | |
- (void)dealloc { | |
[title release]; | |
[subTitle release]; | |
[super dealloc]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment