How do I change navigationBar font in Swift?
Try this:
self.navigationController.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "CaviarDreams", size: 20)!]
Edit: Now, UIFont must be unwrapped to be able to be used here.
Swift 5 (+ safe handling of optional UIFont
)
self.navigationController?.navigationBar.titleTextAttributes = [ NSAttributedString.Key.font: UIFont(name: "Caviar-Dreams", size: 20) ?? UIFont.systemFont(ofSize: 20)]
Using Swift, I added this to AppDelegate.swift
in
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().titleTextAttributes = [
NSFontAttributeName: UIFont(name: "DINNextLTW04-Regular", size: 20)!
]
return true
}
Hope it helps!