首先新建 MyNavController: UINavigationController
在 override func viewDidLoad()方法里面自定义
导航栏样式
//导航栏背景颜色
UINavigationBar.appearance().barTintColor = HEX(hexValue: 0xFFFFFF)
//导航栏字体样式
UINavigationBar.appearance().titleTextAttributes = [.font:kSystemFont(font: 18),.foregroundColor:HEX(hexValue: 0x1E1E1E)]
//去掉导航栏阴影
UINavigationBar.appearance().shadowImage = UIImage.init()
//导航栏BarButtonItem颜色
UINavigationBar.appearance().tintColor = HEX(hexValue: 0x1E1E1E)
自定义返回按钮
let tmpImage = UIImage.init(named: "nav_back_white")
UINavigationBar.appearance().backIndicatorImage = tmpImage
UINavigationBar.appearance().backIndicatorTransitionMaskImage = tmpImage
UINavigationBar.appearance().isTranslucent = false
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -1000,vertical: 0), for: .default)
效果
Simulator Screen Shot - iPhone 12 mini - 2021-05-29 at 11.53.31.png