let allNavigationBar = UINavigationBar.appearance()
//设置allNavigationBar的属性...
navigationBar.barTintColor = UIColor.blackColor()
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
if let barFont = UIFont(name: "Avenir-Light", size: 24.0) {
navigationBar.titleTextAttributes = [
NSForegroundColorAttributeName : UIColor.whiteColor(),
NSFontAttributeName : barFont
]
}
- 更改返回按钮文字
例如: 页面1条转到页面2,更改页面2返回按钮的标题,把下面代码加入页面1的viewDidLoad方法中
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
let allBarButtonItem = UIBarButtonItem.appearance()
allBarButtonItem.setBackButtonTitlePositionAdjustment(UIOffset(horizontal: 0, vertical: -60), for: .default)
navigationBar.tintColor = UIColor.white
navigationBar.isTranslucent = false
- 设置主界面隐藏navigationBar,跳转后显示出来
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
}
navigationController?.interactivePopGestureRecognizer?.isEnabled = false