Search code examples
iosios6uinavigationbar

How to prevent UINavigationBar items hiding if title is long in iOS 6?


I have a problem with UINavigationBar in iOS 6: if navigation bar has too long title, then second (there are two button items) of right bar button items becomes hidden. iOS 7 is okay (must be fixed)

How to prevent such behaviour?


Solution

  • For this you can customize the title label of UINavigationBar. You can set its minimumFontSize property so make the text adjustable.

    OR

    For iOS 6 you can use below code, so that you can provide a custom label:

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    label.textAlignment = UITextAlignmentCenter;
    [label setFont:[UIFont boldSystemFontOfSize:16.0]];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setText:text];
    [self.navigationController.navigationBar.topItem setTitleView:label];