backBarButtonItem gets renamed in iOS 7 when there is a long title

☆樱花仙子☆ 提交于 2019-12-21 09:15:05

问题


One behavior I observed in iOS 7 is that the title of the backBarButtonItem of a UINavigationItem get's renamed if the title of the currently displayed view controller is too long. Too lazy to explain so here are some photos:

As you can see, when the title is too long, the back button gets renamed to "Back" regardless of what it was previously. If the title is even longer, the back button doesn't show any text, just the left arrow image.

Does anyone know how to disable this behavior? I would like the back button to stay exactly what I want it to be and not get renamed. Thanks

EDIT

I created a dirty solution by manually constraining the width of the title of the view controller. I discovered that the font of the title on iPhone is System Bold 17.0, so I do a check for what the size the title will be before setting it (via the sizeWithAttributes: method of strings), and trim characters off the end of the title until the size is shorter than the length that causes the back button to get renamed.


回答1:


iOS 7 will automatically replace your back button title with "Back" or even remove the title altogether in order to fit the title of current navigation item. You probably shouldn't try to do anything about it except maybe try and make your titles shorter.

if you want to make short title you can do as below

self.title = @"SOME REALLY LONG NAVIGATION BAR TITLE";  
UILabel* label=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)];  
label.text=self.navigationItem.title;  
label.adjustsFontSizeToFitWidth=YES;  
self.navigationItem.titleView=label; 


来源:https://stackoverflow.com/questions/19235524/backbarbuttonitem-gets-renamed-in-ios-7-when-there-is-a-long-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!