Reposition navigationItem.title

In my ViewDidLoad, I'm trying something like this, but it doesn't work:


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


 I want to show a shortcut on the left side of my NavigationBar. Or maybe reposition navigationBar.title

Thanks,

+5
source share
1 answer

You can configure the display of the title of the navigation position in UILabel with left 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];

An element title created in this way also allows buttons on the navigation bar and does not overlap them.

+16
source

All Articles