简体   繁体   中英

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?

我会在里面添加一个带有嵌入式UILabeltitleView ,以完全控制标题的显示方式以及它可以“增长”的程度。

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM