设置NavigationBar标题字体

时间:2016-03-21 11:43:29

标签: ios swift uinavigationbar uifont

我一直在寻找一种方法来改变navigationBar中的标题字体,并在下面尝试但没有任何反应,字体在UILabel上工作正常等等。

UINavigationBar.appearance().titleTextAttributes = [
    NSFontAttributeName: UIFont(name: "SourceSansPro-Regular", size: 18) ?? UIFont.systemFontOfSize(18)
]

1 个答案:

答案 0 :(得分:0)

[[UINavigationBar appearance] setTitleTextAttributes:@{
    UITextAttributeTextColor : [UIColor whiteColor],
    UITextAttributeTextShadowColor : [UIColor blackColor],
    UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
    UITextAttributeFont : [UIFont fontWithName:@"System" size:25.0]
}];

in swift

        UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.whiteColor(), 
    UITextAttributeTextShadowColor: UIColor.blackColor(), 
    UITextAttributeTextShadowOffset: NSValue(UIOffset: UIOffsetMake(1, 0)), 
UITextAttributeFont: UIFont(name: "System", size: 25.0)]