我有以下代码:
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 :(得分:4)
您可以通过Storyboard更改导航栏标题属性或尝试此操作:
nav1.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "AvenirNext-UltraLight", size: 24)!, NSForegroundColorAttributeName: UIColor.whiteColor()]
答案 1 :(得分: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
}