Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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
Add Comment
Please, Sign In to add comment