Ios 导航栏标题不加粗
当我在情节提要中时,导航栏标题在情节提要中默认显示为粗体,但当您在模拟器和设备中运行应用程序时,它不是粗体。令人烦恼的是,无法从interface builder更改字体大小 下面您可以看到interface builder和模拟器上显示的内容之间的差异 界面生成器: 模拟器: 我知道我可以使用如下方式更改字体:Ios 导航栏标题不加粗,ios,iphone,swift,fonts,Ios,Iphone,Swift,Fonts,当我在情节提要中时,导航栏标题在情节提要中默认显示为粗体,但当您在模拟器和设备中运行应用程序时,它不是粗体。令人烦恼的是,无法从interface builder更改字体大小 下面您可以看到interface builder和模拟器上显示的内容之间的差异 界面生成器: 模拟器: 我知道我可以使用如下方式更改字体:self.navigationController?.navigationBar.titleTextAttributes=[NSFontAttributeName:UIFont(na
self.navigationController?.navigationBar.titleTextAttributes=[NSFontAttributeName:UIFont(name:“YOUR-font-name-WEIGHT”,size:24)!
这将是完美的,但我想保持默认的SF字体的字体
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize:24, weight: .bold)]
是否有解决方法?发生这种情况的原因是什么?只需使用
UIFont.systemFont
即可获得默认的SF字体
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize:24, weight: .bold)]
在
viewDidLoad
中使用此代码更改字体大小
self.navigationController?.navigationBar.titleTextAttributes = [
NSFontAttributeName: UIFont.systemFont(ofSize: 20, weight: UIFontWeightHeavy)
]
对于swift 4:
self.navigationController?.navigationBar.titleTextAttributes = [
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)
]
在模拟器中,它看起来像
有了这个代码,它看起来像是雨燕4:
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.heavy)]
看起来像一个bug-你在设备上测试过吗?最终这就是你所关心的。是的,它也在设备上。检查编辑使用这个(翻译成Swift):UIFont*font=[UIFont systemFontOfSize:24.0f weight:UIFontWeightBold];您在代码中还做了什么吗?我刚刚做了一个快速测试,使用7+for IB设计模式和7+模拟器,我得到了完全相同的字体外观(当然,模拟器的大小是IB中画布的3倍)。。。