2016-04-03 28 views
1

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

但最後一行沒有改變導航欄 的標題字體我應該怎麼辦?

+0

嘗試較小的字體大小。 – Darko

+0

你確定知道字體沒有改變嗎?許多字體看起來非常相似。 – Darko

回答

4

您可以通過改變故事板導航欄標題屬性或試試這個:

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

您可以創建自己的titleview的是這樣的:

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 
    }