添加UINavigationBar改变了UITabBar

时间:2017-08-04 07:46:44

标签: swift3 uinavigationcontroller uinavigationbar ios10 uitabbar

所以我正在构建一个选项卡式应用程序,并且该设计需要在某些应用程序页面上调用UINavigationBar。将导航栏添加到我的一个选项卡式ViewControllers后,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()
}
    ...

正确显示 correct

显示不正确 Incorrect

非常感谢任何建议或提示!

1 个答案:

答案 0 :(得分:1)

尝试使用以下代码更改UITabBar背景颜色 -

UITabBar.appearance().barTintColor = UIColor.black

希望它有所帮助!