Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've used custom title labels for my nav bars in every app I have in the app store. I've tested many different ways of doing so and by <em>far</em> the easiest way to use a custom label in a navigation bar is to completely ignore <code>titleView</code> and insert your label directly into <code>navigationController.view</code>.</p> <p>With this approach, it's easy to have the title label's frame always match the navigationBar's frame -- even if you are using a custom navBar with a non-standard size.</p> <pre><code>- (void)viewDidLoad { [self.navigationController.view addSubview:self.titleLabel]; [super viewDidLoad]; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation { [self frameTitleLabel]; } - (UILabel *) titleLabel { if (!titleLabel) { titleLabel = [[UILabel alloc] initWithFrame:self.navigationController.navigationBar.frame]; titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18]; titleLabel.text = NSLocalizedString(@"Custom Title", nil); titleLabel.textAlignment = UITextAlignmentCenter; titleLabel.lineBreakMode = UILineBreakModeTailTruncation; } return titleLabel; } - (void) frameTitleLabel { self.titleLabel.frame = self.navigationController.navigationBar.frame; } </code></pre> <p>The one caveat to this approach is that your title can flow over the top of any buttons you have in the navBar if you aren't careful and set the title to be too long. But, IMO, that is a lot less problematical to deal with than 1) The title not centering correctly when you have a rightBarButton or 2) The title not appearing if you have a leftBarButton.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload