[英]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.