change navigation bar title font - swift

Try this:

Objective-C

[[UINavigationBar appearance] setTitleTextAttributes:attrsDictionary];

Swift 3

self.navigationController.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "CaviarDreams", size: 20)!]

Swift 4

self.navigationController.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "CaviarDreams", size: 20)!]

Proper way how to set the font for every view controller in Swift (using Appearance proxy):

Swift 5 (and 4.2)

let attributes = [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue-Light", size: 17)!]
UINavigationBar.appearance().titleTextAttributes = attributes

Swift 4

let attributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Light", size: 17)!]
UINavigationBar.appearance().titleTextAttributes = attributes

Swift 3

let attributes = [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 17)!]
UINavigationBar.appearance().titleTextAttributes = attributes

You can do this in Storyboard as well, there is a bug in Xcode 10.1 of doing this here is a trick to overcome this as well.

Step 1 - Choose System from Font

enter image description here

Step 2 - Then again choose Custom and it will show all the fonts.

enter image description here


SWIFT 4.x

To Change the Navigation bar title font for both Normal & Large Title above iOS 11.x

let navigation = UINavigationBar.appearance()

let navigationFont = UIFont(name: "Custom_Font_Name", size: 20)
let navigationLargeFont = UIFont(name: "Custom_Font_Name", size: 34) //34 is Large Title size by default

navigation.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: navigationFont!]

if #available(iOS 11, *){
    navigation.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white, NSAttributedStringKey.font: navigationLargeFont!]
}

Large Title has to be set true in Navigation bar.


Swift 5 Easy way

//Programatically
self.navigationController!.navigationBar.titleTextAttributes = [NSAttributedString.Key.font: UIFont(name: "Helvetica Neue", size: 40)!]

Physically

enter image description here

enter image description here

enter image description here

enter image description here