我只为特定的rootViewController设置了UINavigationBar标题。我在VC的viewWillAppear方法中编写了下面的代码,并且我还为下一个viewController设置了默认值。我得到“Zapfino”字体但问题是,当我从下一个VC按“后退”时,我得到了根VC的默认标题字体。
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont(name: "Zapfino", size: 18)!]
答案 0 :(得分:0)
在您设置默认字体时的下一个viewController中,在该文件中需要再次设置视图中的特定根ViewController字体将消失下一个viewController的方法。所以你可以找回你的字体。
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(true)
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1), NSFontAttributeName : UIFont(name: "System", size: 12.0)!]
}
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName : #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1), NSFontAttributeName : UIFont(name: "System", size: 17.0)!]
}