How to change the font and text color of the title of UINavigationBar

前端 未结 6 668
滥情空心
滥情空心 2021-01-07 18:05

I want to be change the font of the title to Avenir, and I want to make it white. Here is my code in the viewDidLoad method:

UINavigationBar.app         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 18:13

    In Swift 5:

    let appearance = UINavigationBarAppearance()
        appearance.titleTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.white,
            NSAttributedString.Key.font: UIFont(name: "Avenir", size: 20)!]
        appearance.largeTitleTextAttributes = [
            NSAttributedString.Key.foregroundColor: UIColor.white,
            NSAttributedString.Key.font: UIFont(name: "Avenir", size: 35)!]
    

    Code here are for Title and Large title. you can also remove custom font if you want system font.

提交回复
热议问题