UINavigationBar 的添加改变了 UITabBar 的背景颜色
Addition of UINavigationBar has changed the background color of UITabBar
所以我正在构建一个选项卡式应用程序,并且设计要求在应用程序的某些页面上使用 UINavigationBar。将导航栏添加到我的一个选项卡式 ViewController 后,UITabBar 的颜色从最初设置的颜色(蓝绿色)变为灰色。我试过在我的 AppDelegate 中设置 TabBar 背景颜色(在所有其他选项卡上工作正常),我试过在自定义 TabBar View Controller 中本地设置它(根本不影响颜色),我什至尝试设置它在特定的视图控制器本身。我也试过设置 runtim 属性 但无济于事。我不知道接下来要尝试什么。我已经在下面发布了代码和屏幕截图。
AppDelegate.swift
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()
}
...
正确显示
显示不正确
任何建议或技巧将不胜感激!
试试下面的代码来改变 UITabBar 的背景颜色-
UITabBar.appearance().barTintColor = UIColor.black
希望对您有所帮助!
所以我正在构建一个选项卡式应用程序,并且设计要求在应用程序的某些页面上使用 UINavigationBar。将导航栏添加到我的一个选项卡式 ViewController 后,UITabBar 的颜色从最初设置的颜色(蓝绿色)变为灰色。我试过在我的 AppDelegate 中设置 TabBar 背景颜色(在所有其他选项卡上工作正常),我试过在自定义 TabBar View Controller 中本地设置它(根本不影响颜色),我什至尝试设置它在特定的视图控制器本身。我也试过设置 runtim 属性 但无济于事。我不知道接下来要尝试什么。我已经在下面发布了代码和屏幕截图。
AppDelegate.swift
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()
}
...
正确显示
显示不正确
任何建议或技巧将不胜感激!
试试下面的代码来改变 UITabBar 的背景颜色-
UITabBar.appearance().barTintColor = UIColor.black
希望对您有所帮助!