ios - 设置导航栏标题字体

标签 ios swift uinavigationbar uifont

我一直在寻找一种更改导航栏中标题字体的方法,并进行了以下尝试,但没有任何反应,该字体在 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/

相关文章:

ios - 在 subview Controller 中显示导航栏

ios - 如何在其他 View Controller 中获取 nsuserdefault 值

android - iOS能像安卓一样接收广播吗?

ios - 自定义 UIPageControl 的位置

swift - 从 Swift 函数获取通用类型 UIView

ios - 我的 UITableView 中没有显示任何数据

ios - 如何自定义来自对象库的导航栏

ios - 即使在 player.status == .readyToPlay 之后,AVPlayerItem.duration 仍返回 NaN

ios - Objective C中两个对象的相等性

ios - 如何从 Xcode 中导航栏上的后退按钮中删除文本?