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
var navigationController = UINavigationController()
navigationController.viewControllers = [mainViewController]
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)
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)
如何使两者显示相同的半透明颜色导航栏?使用此方法在全局所有位置更改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。这将反映应用程序中的任何地方。