How do i change navigationBar font in Swift?

前端 未结 9 1265
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 20:16

How do I change the NavigationBar font in Swift?

This is what I have tried so far, but receiving an error (I have correctly implemented CaviarDreams

9条回答
  •  执笔经年
    2020-12-23 20:54

    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)]
    

提交回复
热议问题