views:

315

answers:

1

Hi,

In my ViewDidLoad I try something like that but its not working:


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10,2,60,14)];
label.autoresizingMask = UIViewAutoresisingFlecibleWidth;
[self.navigationController.navigationBar addSubview:label];


I want to display a label in the left part of my NavigationBar. Or maybe change the navigationBar.title position

Thanks,

A: 

You can do set navigation item's title view to UILabel with left text alignment:

UILabel* lbNavTitle = [[UILabel alloc] initWithFrame:CGRectMake(0,40,320,40)];
lbNavTitle.textAlignment = UITextAlignmentLeft;
lbNavTitle.text = NSLocalizedString(@"Hello World!",@"");
self.navigationItem.titleView = lbNavTitle;
[lbNavTitle release];

Created this way item's title also tolerates buttons on navigation bar and does not overlap them.

Vladimir
What if some one is having the rightBarButton? This will not work right?
Manjunath
why? it seems navigation item automatically shrinks its title view if left or right button is present. This approach works for me...
Vladimir
that works for me too. Or you can also try [self.navigationcontroller.navigationBar.topItem setTitleView:yourlabel];
ludo