简体   繁体   English

如何根据文本调整导航后退按钮的大小(不使用自定义图像)

[英]How to resize navigation back button according to text (not using custom image)

I have View Controller inside of Navigation Controller. 我在导航控制器中有View Controller。 It has default back button with title of previous controller in navigation controller's stack. 它具有默认的后退按钮,在导航控制器的堆栈中带有上一控制器的标题。 But button dont resize to text width. 但是按钮不会调整为文本宽度。 So it looks like this: http://gyazo.com/0f94d7802354cadaee7d4aa38b1eea8e (I'm sorry i can't add images) 所以看起来像这样: http : //gyazo.com/0f94d7802354cadaee7d4aa38b1eea8e (对不起,我无法添加图像)

But when I open setting in simulator I see that text fit back button: http://gyazo.com/d3a512ce41885896a4ebe04ed1ca2a0c 但是,当我在模拟器中打开设置时,我看到该文本适合后退按钮: http : //gyazo.com/d3a512ce41885896a4ebe04ed1ca2a0c

How can I reach the same behavior? 我怎样才能达到相同的行为? Thanks. 谢谢。

I've found that the back button will resize automatically to fit the text. 我发现后退按钮会自动调整大小以适合文本。 Are you customizing your title? 您要自定义标题吗? It doesn't look like the default so perhaps this is the problem. 它看起来不像默认值,所以也许是问题所在。 You could try truncating the title manually or making a custom back button: 您可以尝试手动截断标题或制作自定义后退按钮:

self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:
@"Custom Back Title" style:UIBarButtonItemStyleBordered target:nil action:nil]
autorelease];

This should be added to the view controller one level up (so the one that would be displayed by tapping back, not the one in which the button appears). 应该将其上一级添加到视图控制器中(这样一来,通过点按即可显示的内容,而不是显示按钮的内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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