簡體   English   中英

UINavigationBar backgroundColor無法與UITabBar一起使用

[英]UINavigationBar backgroundColor not working with UITabBar

我正在使用UINavigationController並在didFinishLaunching ...中設置背景顏色:

self.navController.backgroundColor = UIColor.green

如第一個圖像所示,它在第一個視圖控制器中運行良好。 在第二個視圖控制器中(僅使用按鈕的segue按下),我有一個UITabBar(沒有UITabBarController),並且那里的背景色不起作用。 如果我刪除了UITabBar,它將起作用。

正確的導航欄背景色

導航欄背景顏色錯誤

該項目從未包含任何其他代碼。 如果我使用barTintColor而不是backgroundColor,它將起作用,但是我認為效果不佳。

有人知道我該如何解決嗎?

您必須為導航欄的背景色設置屬性TintColor

在Objective-c中

[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];

迅速

navigationController.navigationBar.barTintColor = UIColor.greenColor()

self.navigationController?.navigationBar.barTintColor = UIColor.GreenColor()

要么

UINavigationBar.appearance().barTintColor = .blackColor()

要么

[navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

您可以這樣使用barTintColor屬性:

self.navigationController?.navigationBar.barTintColor = UIColor.green

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM