Ios swift:导航栏中标题的字体

Ios swift:导航栏中标题的字体,ios,swift,fonts,navbar,Ios,Swift,Fonts,Navbar,在AppDelegate.swift中,我有以下代码: let nav1 = UINavigationController() let mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller nav1.viewControllers = [mainView] nav1.navigationBar.topItem?.title = "JT"

在AppDelegate.swift中,我有以下代码:

let nav1 = UINavigationController()
    let mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
    nav1.viewControllers = [mainView]
nav1.navigationBar.topItem?.title = "JT"
    nav1.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]
但最后一行并没有改变导航栏标题的字体
我应该怎么做?

您可以通过故事板更改导航栏标题属性,或者尝试以下操作:

nav1.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]

您可以通过故事板更改导航栏标题属性,或尝试以下操作:

nav1.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!,  NSForegroundColorAttributeName: UIColor.whiteColor()]

您可以创建自己的标题视图,如下所示:

 let label=UILabel(frame: nav1.navigationBar.frame)
    label.textAlignment=NSTextAlignment.Center
    label.font=UIFont(name: "FONT HERE", size: 27)
    label.text="TITLE HERE"
    label.textColor=UIColor.blackColor()
    for item in nav1.navigationBar.items!{
       item.titleView=label 
    }

您可以创建自己的标题视图,如下所示:

 let label=UILabel(frame: nav1.navigationBar.frame)
    label.textAlignment=NSTextAlignment.Center
    label.font=UIFont(name: "FONT HERE", size: 27)
    label.text="TITLE HERE"
    label.textColor=UIColor.blackColor()
    for item in nav1.navigationBar.items!{
       item.titleView=label 
    }

试试小一点的字体。你确定字体没有改变吗?许多字体看起来非常相似。请尝试较小的字体大小。您确定字体没有更改吗?许多字体看起来很相似。