繁体   English   中英

导航栏后退按钮文本颜色恢复为默认值

[英]Navigation Bar back button text colour reverts to default

我的应用程序中有一些代码可以更改导航栏字体的颜色。 问题是,在我开发代码时,我一直在添加代码来执行此操作,但是我没有检查过我真正需要的部分。 我想知道这是否导致了我一直遇到的问题。

基本上,偶尔(当我没有弄清楚是什么原因时),当我打开应用程序时,后退按钮文本的颜色会恢复为默认的蓝色。

这是我的代码:

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

    let appearanceTab = UITabBarItem.appearance()
    let appearanceNav = UINavigationBar.appearance()

    let attributesTabBar = [NSFontAttributeName:UIFont(name: "Avenir", size: 11)]
    appearanceTab.setTitleTextAttributes(attributesTabBar, forState: .Normal)

    appearanceNav.titleTextAttributes = [NSFontAttributeName:UIFont(name: "Avenir", size: 25)]
}

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController?.navigationBar.barTintColor = UIColorFromRGB(0x009051)
    UINavigationBar.appearance().barTintColor = UIColorFromRGB(0x009051)
    UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    UITabBar.appearance().tintColor = UIColor.newBlueColor()
}

我尝试删除代码的不同部分,但无法确定问题所在。 有任何想法吗?

下面的代码添加到AppDelegate.swift didFinishLaunchingWithOptions功能

var navigationBarAppearace = UINavigationBar.appearance()

navigationBarAppearace.tintColor = uicolorFromHex(0xffffff) // White color
navigationBarAppearace.barTintColor = uicolorFromHex(0x034517) // Green shade

// change navigation item title color
navigationBarAppearace.titleTextAttributes =[NSForegroundColorAttributeName:UIColor.whiteColor()]

我曾经给别人一个解决方案,我保存了代码。 用这种方式玩一些。

var attributes = [NSForegroundColorAttributeName: UIColor.greenColor(),NSFontAttributeName: UIFont(name: "Avenir", size: 30)]
        self.navigationController?.navigationBar.titleTextAttributes = attributes

暂无
暂无

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

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