我一直在寻找一种更改导航栏中标题字体的方法,并进行了以下尝试,但没有任何反应,该字体在 UILabel 等上工作正常。
UINavigationBar.appearance().titleTextAttributes = [
NSFontAttributeName: UIFont(name: "SourceSansPro-Regular", size: 18) ?? UIFont.systemFontOfSize(18)
]
最佳答案
[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeTextShadowColor : [UIColor blackColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
UITextAttributeFont : [UIFont fontWithName:@"System" size:25.0]
}];
快速
UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.whiteColor(),
UITextAttributeTextShadowColor: UIColor.blackColor(),
UITextAttributeTextShadowOffset: NSValue(UIOffset: UIOffsetMake(1, 0)),
UITextAttributeFont: UIFont(name: "System", size: 25.0)]
关于ios - 设置导航栏标题字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36130124/