Many a times, we need the UINavigation bar title to have more than one line, we can do this easily by customizing the titleView of the UINavigationItem.

The following method would help you get started:

- (void)customNavBarTitle: (NSString *)titleStr
{
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(([self.title length] < 10 ? UITextAlignmentCenter : UITextAlignmentLeft), 0, 480,44)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.numberOfLines = 2;
titleLabel.font = [UIFont boldSystemFontOfSize: 14.0f];
titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
titleLabel.textAlignment = ([self.title length] < 10 ? UITextAlignmentCenter : UITextAlignmentLeft);
titleLabel.textColor = [UIColor whiteColor];
titleLabel.text = titleStr;
self.navigationItem.titleView = titleLabel;
[titleLabel release];
}

Sphere: Related Content

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.