Skip to content

Instantly share code, notes, and snippets.

@canaksoy
Last active July 23, 2016 11:07
Show Gist options
  • Save canaksoy/2495b9bf5ed73616ad2ce3372edf51f4 to your computer and use it in GitHub Desktop.
Save canaksoy/2495b9bf5ed73616ad2ce3372edf51f4 to your computer and use it in GitHub Desktop.
NavigationBarTitleWithSubtitleView
#import <UIKit/UIKit.h>
@interface NavigationBarTitleWithSubtitleView : UIView
- (void) setTitleText: (NSString *) aTitleText;
- (void) setDetailText: (NSString *) aDetailText;
@end
#import "NavigationBarTitleWithSubtitleView.h"
@interface NavigationBarTitleWithSubtitleView()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@end
@implementation NavigationBarTitleWithSubtitleView
@synthesize titleLabel;
@synthesize detailLabel;
- (id) init
{
self = [super initWithFrame:CGRectMake(0, 0, 200, 44)];
if (self) {
[self setBackgroundColor: [UIColor clearColor]];
[self setAutoresizesSubviews:YES];
CGRect titleFrame = CGRectMake(0, 2, 200, 24);
titleLabel = [[UILabel alloc] initWithFrame:titleFrame];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.shadowColor = [UIColor darkGrayColor];
titleLabel.shadowOffset = CGSizeMake(0, -1);
titleLabel.text = @"";
titleLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:titleLabel];
CGRect detailFrame = CGRectMake(0, 24, 200, 44-24);
detailLabel = [[UILabel alloc] initWithFrame:detailFrame];
detailLabel.backgroundColor = [UIColor clearColor];
detailLabel.font = [UIFont systemFontOfSize:13];
detailLabel.textAlignment = UITextAlignmentCenter;
detailLabel.textColor = [UIColor whiteColor];
detailLabel.shadowColor = [UIColor darkGrayColor];
detailLabel.shadowOffset = CGSizeMake(0, -1);
detailLabel.text = @"";
detailLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:detailLabel];
[self setAutoresizingMask : (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin)];
}
return self;
}
- (void) setTitleText: (NSString *) aTitleText
{
[self.titleLabel setText:aTitleText];
}
- (void) setDetailText: (NSString *) aDetailText
{
[self.detailLabel setText:aDetailText];
}
@end
NavigationBarTitleWithSubtitleView *navigationBarTitleView = [[NavigationBarTitleWithSubtitleView alloc] init];
[self.navigationItem setTitleView: navigationBarTitleView];
[navigationBarTitleView setTitleText:@"Main title"];
[navigationBarTitleView setDetailText:@"Subtitle"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment