自定义导航
class MainNavigationController: UINavigationController {
var statusLabel: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
//导航一些基本设置
UINavigationBar.appearance().barStyle = .default
self.navigationBar.barTintColor = UIColor.init(hexString: "2BB465")
// UINavigationBar.appearance().setBackgroundImage(UIImage.init(named: "navBgImage"), for: .default)
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UINavigationBar.appearance().backIndicatorImage = UIImage(named: "c-backlt")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "c-backlt")
UINavigationBar.appearance().tintColor = UIColor.white
}
//导航初始化的一些方法
required override init(rootViewController: UIViewController) {
super.init(rootViewController: rootViewController)
}
// required init?(coder aDecoder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
// }
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
//*************当导航push的时候 *********************
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
//全文重点!*********************************************************
if self.childViewControllers.count == 1 {
viewController.hidesBottomBarWhenPushed = true
}
//这里是返回按钮的设置
viewController.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .done, target: nil, action: nil)
super.pushViewController(viewController, animated: animated)
}
}
网友评论