Question

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?

Was it helpful?

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];

OTHER TIPS

I would add a titleView with an embedded UILabel inside to have full control of how the title is displayed and how much it can "grow".

This question is the same as Back button title missing with long screen title in iOS 7

And the answer is the same answer I gave there: https://stackoverflow.com/a/22029442/341994

I quote that answer:

Make your screen title smaller. You can take control of it by using a titleView that's a UILabel. The advantage is that you can set its size, and that it can truncate its text and/or make the text occupy two lines if the text is too big (rather than just growing, as the title does).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top