Ios 导航条颜色

Ios 导航条颜色,ios,uitableview,uinavigationcontroller,uinavigationbar,Ios,Uitableview,Uinavigationcontroller,Uinavigationbar,我编写了以下代码来设置导航栏和视图控制器的视图: AppDelegate上的导航栏: var navigationController = UINavigationController() navigationController.viewControllers = [mainViewController] 主视图控制器A: self.view.backgroundColor = UIColor.blue let fullScreenRect = UIScreen.main.bounds

我编写了以下代码来设置导航栏和视图控制器的视图:

  • AppDelegate上的导航栏:

    var navigationController = UINavigationController()
    
    navigationController.viewControllers = [mainViewController]
    
  • 主视图控制器A:

    self.view.backgroundColor = UIColor.blue
    let fullScreenRect = UIScreen.main.bounds
    let buttonSize:CGFloat = 60
    let viewLogButton = UIButton(frame: CGRect(x: 0, y: fullScreenRect.size.height-buttonSize, width:fullScreenRect.size.width, height: buttonSize))
    viewLogButton.setTitle("View Log", for: UIControlState.normal)
    viewLogButton.setTitleColor(UIColor.white, for: .normal)
    viewLogButton.setTitleColor(UIColor.blue, for: .highlighted)
    viewLogButton.backgroundColor = UIColor.blue
    viewLogButton.addTarget(self, action: #selector(viewLogButtonPressed), for: .touchUpInside)
    self.view.addSubview(viewLogButton)
    self.webView.frame = CGRect(x: 0, y:    UIConstants.NAVIGATION_BAR_HEIGHT+UIConstants.STATUS_BAR_HEIGHT, width: fullScreenRect.size.width, height: fullScreenRect.size.height-buttonSize-UIConstants.NAVIGATION_BAR_HEIGHT-UIConstants.STATUS_BAR_HEIGHT)
    self.view.addSubview(self.webview)
    
  • 这导致顶部导航栏的视图显示半透明的蓝色。

    然后,我在另一个ViewController B(表视图控制器)中执行相同的操作:

  • 主视图控制器B:

    let tableView = UITableView()
    let screenSize: CGRect = UIScreen.main.bounds    
    self.view.backgroundColor = UIColor.blue
    let screenWidth = screenSize.width
    let screenHeight = screenSize.height
    tableView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)    
    self.view.addSubview(tableView)
    
  • 我想知道为什么MainViewController A中有半透明的导航栏,但MainViewController B不能显示它


    如何使两者显示相同的半透明颜色导航栏?

    使用此方法在全局所有位置更改UINavigationBar,从
    AppDelegate

    func setupNaviBarAppearnce() {
    
        UINavigationBar.appearance().isOpaque = true
        UINavigationBar.appearance().isTranslucent = true
        UINavigationBar.appearance().barTintColor = Theme.AppMainPurpleColor
        UINavigationBar.appearance().tintColor = UIColor.white
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName:Typography.navigationTitle!,NSForegroundColorAttributeName:UIColor.white]
    }
    

    注意:您需要根据您的需求和UI对其进行修改

    我尝试过了。iTranslucent、barTintColor在iOS10中不可用。不,它是
    @可用的(iOS 3.0,*)open var iTranslucent:Bool//在iOS 6及更早版本中默认为否。如果barStyle设置为UIBarStyleBlackTranslucent,则始终为“是”(适用于条色
    。@可用(iOS 7.0,*)打开变量barTintColor:UIColor?//默认值为nil
    只需命令并单击
    bartincolor
    是否有帮助,或者你需要更多的东西?事实上,我的问题是为什么ViewControllerA的顶部有一个半透明的条,而ViewControllerA的B上没有这样的颜色。我不明白是我的代码的哪一部分导致了这一点。我无法在IOS10子类NavigationController和add customize attributes中使用appearance().isTranslucent。这将反映应用程序中的任何地方。