繁体   English   中英

导航栏标题不粗体

[英]Navigation bar title not bold

当我在情节提要中时,导航栏标题在情节提要中默认显示为粗体,但是当您在模拟器和设备中运行应用程序时,它不是粗体。 令人讨厌的是,无法从界面构建器更改字体大小。

在下面,您可以看到界面生成器和模拟器之间的区别。

界面生成器: 界面生成器

模拟器: 在此处输入图片说明

我知道我可以使用以下方式更改字体: self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "YOUR-FONT-NAME-WEIGHT", size: 24)! 那将是完美的,但是我想将字体保持为默认的SF字体。

有解决方法吗? 有什么原因会发生这种情况?

viewDidLoad使用此代码来更改字体大小

self.navigationController?.navigationBar.titleTextAttributes = [
    NSFontAttributeName: UIFont.systemFont(ofSize: 20, weight: UIFontWeightHeavy)
]

快速4:

self.navigationController?.navigationBar.titleTextAttributes = [
    NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)
]

在模拟器之前,它看起来像 在此处输入图片说明

有了这段代码,它看起来像 在此处输入图片说明

只需使用UIFont.systemFont即可获取默认的SF字体。

self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize:24, weight: .bold)]

斯威夫特4:

self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)]

暂无
暂无

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

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