[英]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.