Swift3 UINavigationBar的添加改变了UITabBar的背景色
因此,我正在构建一个选项卡式应用程序,该设计要求在应用程序的某些页面上使用UINavigationBar。将导航栏添加到我的一个选项卡式ViewController后,UITabBar的颜色从最初设置为(蓝绿色)的颜色更改为灰色。我曾尝试在AppDelegate中设置TabBar背景色(在所有其他选项卡上都可以正常工作),我曾尝试在自定义TabBar视图控制器中本地设置它(根本不影响颜色),我甚至尝试在特定视图控制器本身中设置它。我也尝试过设置runtim属性,但没有效果。我不知道下一步该做什么。我已经在下面发布了代码和屏幕截图 AppDelegate.swiftSwift3 UINavigationBar的添加改变了UITabBar的背景色,swift3,uinavigationcontroller,uinavigationbar,ios10,uitabbar,Swift3,Uinavigationcontroller,Uinavigationbar,Ios10,Uitabbar,因此,我正在构建一个选项卡式应用程序,该设计要求在应用程序的某些页面上使用UINavigationBar。将导航栏添加到我的一个选项卡式ViewController后,UITabBar的颜色从最初设置为(蓝绿色)的颜色更改为灰色。我曾尝试在AppDelegate中设置TabBar背景色(在所有其他选项卡上都可以正常工作),我曾尝试在自定义TabBar视图控制器中本地设置它(根本不影响颜色),我甚至尝试在特定视图控制器本身中设置它。我也尝试过设置runtim属性,但没有效果。我不知道下一步该做什么
import Firebase
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let myGreenBG = UIColor(colorLiteralRed: 43/255.0, green: 111/255.0, blue: 109/255.0, alpha: 1.0)
FirebaseApp.configure()
UITabBar.appearance().backgroundColor = myGreenBG
UINavigationBar.appearance().backgroundColor = myGreenBG
return true
}
...
TabBarViewController.swift
导入UIKit
class tabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let myGreenBG = UIColor(colorLiteralRed: 43/255.0, green: 111/255.0, blue: 109/255.0, alpha: 1.0)
//self.tabBar.delegate = self
//Code to render the unselected images in the tab bar
tabBar.backgroundColor = myGreenBG
for items in 0 ..< tabBar.items!.count {
let tabItemIndex = tabBar.items![items]
tabItemIndex.image = tabItemIndex.image!.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
/*for tabBarItem in (self.tabBarController?.tabBar.items!)!{
if !(tabBarItem.
}
}*/
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
...
类选项卡视图控制器:UITabBarController{
重写func viewDidLoad(){
super.viewDidLoad()
设myGreenBG=UIColor(colorLiteralRed:43/255.0,green:111/255.0,blue:109/255.0,alpha:1.0)
//self.tabBar.delegate=self
//用于在选项卡栏中呈现未选定图像的代码
tabBar.backgroundColor=myGreenBG
对于0..
正确显示
错误显示
如果您有任何建议或提示,我们将不胜感激。请尝试下面的代码来更改UITabBar背景色-
UITabBar.appearance().barTintColor = UIColor.black
希望有帮助!uitabar.appearance().backgroundColor=UIColor(colorLiteralRed:43/255.0,green:111/255.0,blue:109/255.0,alpha:1.0)在viewWillApear中尝试此操作,并在VIEWWILLOVERE中重置为以前的状态color@JaydeepVyas不幸的是,这不起作用。似乎将其设置为背景色意味着它在那里,但在导航栏设置添加的任何内容之下。似乎设置barTintColor,正如阿披舍克所建议的那样,是唯一可以重置颜色的方法。尽管在m在上一个示例中,使用backgroundColor属性使其比使用barTintColor显示的阴影亮得多。无论如何,我可以使用此解决方案,所以谢谢!