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

本文介绍三种iOS应用中导航栏的定制方法:全局配置、单页面设置及自定义视图方案,帮助开发者灵活调整导航栏样式。

方法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, 设置类似导航栏效果

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值