Reputation: 13
Does anyone have a clue on how to create a multiline navigation/top bar in iOS? I want something similar to the status line in WhatsApp (the one that displays last seen or the current status information). Any advice would be appreciated.
I want to achieve something like in the image (Francis Whitman / last seen [...]):
Upvotes: 1
Views: 2123
Reputation: 11
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/2, 200)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTextAlignment:NSTextAlignmentCenter];
[label setNumberOfLines:0];
[label setText:_certificate.name];
self.navigationItem.titleView = label;
Upvotes: 0
Reputation: 19071
By default, a UINavigationController
will use the title
property of the currently-displayed view controller for the title in its navigation bar. You can have it display any arbitrary view, however, by setting the titleView
property of the view controller’s navigationItem
property, as so:
// In your view controller’s implementation (.m) file:
- (id)initWithNibName:(NSString *)nibName
bundle:(NSStirng *)nibBundle
{
self = [super initWithNibName:nibName bundle:nibBundle];
if (self) {
UIView *myTitleView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
0.0f,
250.0f,
44.0f)];
[myView setBackgroundColor:[UIColor greenColor]];
[[self navigationItem] setTitleView:myTitleView];
}
return self;
}
Upvotes: 3