设置导航栏颜色、字体属性

方法1:在appdelegate中设置

///全局设置导航栏以及左右item的颜色和大小属性---->此方法需要在appDelegate中调用
func appdelegateConfigNavi() {
    UINavigationBar.appearance().barTintColor = UIColor.white//navibar的背景渲染色
    UINavigationBar.appearance().tintColor = UIColor.red//渲染色
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 18),NSAttributedStringKey.foregroundColor: UIColor.black]
    UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor: UIColor.black], for: UIControlState.normal)
}

方法2: 在每一个自定义的页面中修改,记得一定要在viewwillappear中设置

///设置navigationBar的背景选染色
self.navigationController?.navigationBar.barTintColor = UIColor.white

///标题title属性    
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: isFour ? UIColor.white : UIColor.black]

//左右BarButtonItem属性
self.navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSAttributedStringKey.font: UIFont.systemFont(ofSize: 15), NSAttributedStringKey.foregroundColor: UIColor.red], for: .normal)

方法3:自定义--->自定义一个View, 设置类似导航栏效果

 

你可能感兴趣的:(设置导航栏颜色、字体属性)