我在我的应用中遇到一个问题,特殊的后退按钮改变了字体颜色,没有明显的原因。我已经浏览了所有代码,我看不出任何原因,但是当启动我的应用程序并且转到问题视图控制器时,文本颜色似乎设置为默认的蓝色。
如果我点击转到另一个选项卡,然后返回到此视图控制器,则字体将返回正确的颜色(白色),尽管viewWillAppear / Disappear viewDidAppear / Disappear中没有任何代码。
我用来设置导航栏文字颜色的代码是:
override func awakeFromNib() {
var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)!]
self.navigationController?.navigationBar.titleTextAttributes = attributes
}
这是在使用后退按钮进入视图控制器时被视图控制的视图控制器中。我已尝试将此代码添加到viewWillAppear()
中,但即使这样也没有任何区别。
有没有人知道为什么在发布时我的应用程序没有设置后退按钮文本颜色并需要一个标签开关才能更新?
答案 0 :(得分:0)
请尝试在apear方法中查看相同的代码。然后它应该保持样式到后退按钮
答案 1 :(得分:0)
我认为此代码可以正常使用
self.navigationController?.navigationBar.barTintColor = UIColor.someColor()
//This sets the background colour of the navigation bar
self.navigationController?.navigationBar.tintColor = UIColor.someColor()
// This sets the colour for navigation and bar button items
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "someFont", size: 20)!, NSForegroundColorAttributeName: UIColor.blackColor()]
//This sets the attributed text for the title of the navigation bar
UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont(name: "someFont", size: 17)!], forState: .Normal)
//And this sets the attributed text for the bar button item(s) on the navigation bar (So that includes the back button)
在viewWillAppear中调用它 我希望这有效:)