xcode 在界面生成器中更改导航栏标题字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24660899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:11:42  来源:igfitidea点击:

Changing Navigation Bar Title Font in Interface Builder

iosxcodefontsuinavigationbaruistoryboard

提问by Andorath

I've implemented a Navigation Controller for my View Controller with storyboard. Now i want changing navigation bar title font and size with Attribute Inspector but it doesn't work and i don't understand why. Title color changes but font dont.

我已经为我的带有故事板的视图控制器实现了一个导航控制器。现在我想使用 Attribute Inspector 更改导航栏标题字体和大小,但它不起作用,我不明白为什么。标题颜色会改变,但字体不会。

ps: the color changing is visible only at runtime and not in the storyboard.

ps:颜色变化仅在运行时可见,在故事板中不可见。

Attribute Inspector's properties

Attribute Inspector's properties

回答by

You need to select navigation Bar and then you can set relevant properties. Please check attached image. It might help you.

您需要选择导航栏,然后您才能设置相关属性。请检查附加的图像。它可能会帮助你。

enter image description here

enter image description here

回答by Bart?omiej Semańczyk

When I tried to set the font, my font field was grayed out. But all I needed to do was change type to Systemand then again to Custom. It worked:-) Now I can choose my custom font

当我尝试设置字体时,我的字体字段变灰了。但我需要做的就是将类型更改为System,然后再次更改为Custom. 它有效:-) 现在我可以选择我的自定义字体

回答by danny

For me Bart?omiej Semańczyk's change to system font & change back trick only works to set the font to a particular system-included font. For custom fonts that I've added, the font face gets set to my custom font but it always gets displayed as size ~16 or so regardless of what size I select in the storyboard.

对我来说,Bart?omiej Semańczyk 对系统字体的更改和变回技巧仅适用于将字体设置为特定的系统包含字体。对于我添加的自定义字体,字体设置为我的自定义字体,但无论我在情节提要中选择什么大小,它始终显示为 ~16 左右的大小。

So the best way I can find to do this is to set self.navigationController.navigationBar.titleTextAttributesin the view controller's viewDidLoad method.

所以我能找到的最好方法是self.navigationController.navigationBar.titleTextAttributes在视图控制器的viewDidLoad method.

Note that you don't need to do this in every view controller you push onto this navigation stack, just the first one that gets displayed since it sets the property on the navigationBar itself not on the navigationItem. If you're subclassing UINavigationController already, that's the most logical place to set this but I'd rather not subclass it just for this one line change.

请注意,您不需要在推送到此导航堆栈的每个视图控制器中执行此操作,只需显示第一个视图控制器,因为它将属性设置在导航栏本身而不是导航项上。如果您已经将 UINavigationController 子类化,那么这是设置它的最合乎逻辑的位置,但我宁愿不只是为了这一行更改而将其子类化。