繁体   English   中英

后退按钮文字颜色恢复为默认值

[英]Back button text colour reverts to default

我的应用程序出现问题,没有明显的原因,特定的后退按钮更改了字体颜色。 我已经遍历了所有代码,但看不到任何原因,但是当启动我的应用程序并选择到问题视图控制器时,文本颜色似乎设置为默认的蓝色。

如果我点击以转到其他选项卡,然后返回此视图控制器,则字体将返回正确的颜色(白色),尽管在viewWillAppear / Disappear viewDidAppear / Disappear中没有任何代码。

我用来设置导航栏文本颜色的代码是:

override func awakeFromNib() {
    var attributes = [NSForegroundColorAttributeName: UIColor.whiteColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 24)!]
    self.navigationController?.navigationBar.titleTextAttributes = attributes
}

这是在使用后退按钮进入视图控制器时与之隔离的视图控制器中。 我尝试将这段代码添加到viewWillAppear()但是即使这样也没有任何区别。

有谁知道为什么在启动时我的应用程序未设置后退按钮文本颜色,并且需要使用选项卡开关进行更新?

请尝试在视图将出现的方法中编写相同的代码。

我认为这段代码会工作

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中调用它,我希望它能起作用:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM