当标题很长时,backBarButtonItem会在iOS 7中重命名 [英] backBarButtonItem gets renamed in iOS 7 when there is a long title

查看:133
本文介绍了当标题很长时,backBarButtonItem会在iOS 7中重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS 7中观察到的一个行为是 backBarButtonItem UINavigationItem 的标题被重命名为当前显示的视图控制器的标题太长。太懒了解释所以这里有一些照片:

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

我通过手动约束视图控制器标题的宽度来创建一个脏解决方案。我发现iPhone上的标题字体是 System Bold 17.0 ,所以我在设置之前检查标题的大小(通过 sizeWithAttributes:字符串方法),并在标题末尾修剪字符,直到大小比导致后退按钮重命名的长度短。

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.

推荐答案

iOS 7将自动将后退按钮标题替换为后退,甚至完全删除标题以适合当前导航项的标题。你可能不应该尝试做任何事情,除非尝试让你的标题更短。

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; 

这篇关于当标题很长时,backBarButtonItem会在iOS 7中重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆