更改字体后,导航栏标题不会保持粗体



我使用此代码(基于此答案(将导航栏标题更改为苹果公司的纽约衬线字体。

init() {
// if NavigationBarTitle is with Large Font
if let newYorkDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withDesign(.serif) {
UINavigationBar.appearance().largeTitleTextAttributes = [.font : UIFont(descriptor: newYorkDescriptor, size: 0)]
}
}

导航栏标题以正确的字体和字号显示,但它失去了正常导航栏标题的粗体外观。我该如何恢复?是否缺少粗体或字体大小参数?

bold是字体描述符的一部分,您必须像一样显式添加它

UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle)
.withDesign(.serif)?.withSymbolicTraits(.traitBold)

最新更新