Search code examples
swiftuinavigationbarcustom-font

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


How to set custom font name and custom font weight (font style) for UINavigationBar title?


Solution

  • Use UIFontDescriptor as Font Name and Font Size

    UIFontDescriptor.fontDescriptorWithSymbolicTraits as font style (Bold, Italic, ...)

    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.