我正在開發一個應用程序,其中應用程序的主頁具有隱藏細線的白色導航欄,其餘頁面具有綠色導航欄。到目前爲止,我所做的是將主頁導航欄的代碼放在自己的.swift文件中,但是當我通過主頁上的按鈕導航到其他頁面時(與菜單欄相反) )導航欄仍然設置爲白色。我認爲這是因爲當通過按鈕訪問時,刪除細線的代碼會傳遞到其他頁面。如何在Swift中爲不同頁面撤消發條刪除?
這是我的網頁應該非常像: Homepage & Module
這實際上是模塊頁面的樣子:Module Page Now
這是我使用的代碼 - 不知道是否有人能幫助我弄清楚如何反轉代碼或者是否有其他解決方案。
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Set navigation bar tint/background colour
self.navigationController?.navigationBar.barTintColor = UIColor.whiteColor()
// Set Navigation bar Title colour
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blackColor()]
//Set navigation bar Back button tint colour
self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
//Get Rid of 1px hairline
self.navigationController?.navigationBar.setBackgroundImage(
UIImage(),
forBarPosition: .Any,
barMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
// Set navigation bar tint/background colour
self.navigationController?.navigationBar.barTintColor = UIColor(red: 0/255, green: 127/255, blue: 106/255, alpha: 1)
// Set Navigation bar Title colour
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
//Set navigation bar Back button tint colour
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
//Reverse get Rid of 1px hairline code
/*self.navigationController?.navigationBar.setBackgroundImage(
UIImage(),
forBarPosition: .Any,
barMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()*/
}
你是什麼意思爲「髮際線」? –
@AlessandroOrnano與導航欄底部相鄰的1px線 – zenpain