如何将自定义字体和粗细(样式)设置为 UInavigationbar 标题

How to set custom font and weight (style) to UInavigationbar title

UINavigationBar标题如何设置自定义字体名称和自定义字体粗细(字体样式)?

UIFontDescriptor用作Font NameFont Size

UIFontDescriptor.fontDescriptorWithSymbolicTraits 作为字体样式(粗体、斜体、...)

Swift 2.x:

let fontDec = UIFontDescriptor(name: "FontName", size: 20)
fontDec.fontDescriptorWithSymbolicTraits(.TraitBold)
let font = UIFont(descriptor: fontDec, size: 20)

self.navigationBar.titleTextAttributes = [
    NSFontAttributeName: font,
    NSForegroundColorAttributeName: UIColor.redColor()]

Maybe performance issue.

试试这个代码。 Swift 3x

这可能是设置 nanvigationBar 标题字体和样式的更好方法。

    navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.ANY COLOUR, NSFontAttributeName:UIFont(name:"FontName-FontStyle", size: ANY SIZE)!]

一些字体样式:

    Regular,Bold,BoldItalic,CondensedBlack,CondensedBold,Italic,Light,LightItalic,Thin,ThinItalic,UltraLight,UltraLightItalic

注意:字体样式因字体而异!

Swift 4x:

let newFont = UIFont(名称: "FontName", 大小: 15) 新字体?.fontDescriptor.withSymbolicTraits(.traitBold)