系统导航栏:系统导航栏 在一个NavigationController下共用一个导航栏,对其作出修改是全局修改
NaviBar 构造
|- navigationBar
|- _UIBarBackground
navigationBar上第一个view size比navigationBar 高一个statusBar 刘海屏幕高44 普通高20 y坐标 frame.origin.y (-44/-20)
|-UIImageView
分割线
|-UIVisualEffectView
模糊层 navigationController.navigationBar.translucent 半透明效果
self.navigationController.navigationBar.translucent = NO; 该控件不存在
self.navigationController.navigationBar.translucent = YES; 默认translucent为YES 该控件存在
|-_UIVisualEffectBackdropView
|-_UIVisualEffectFilterView
|- UINavigationItemView
没有设置navigation title 就没有该控件
|-UILabel
label用来展示navigation title
|- UINavigationItemButtonView
|- UILabel
系统默认的字样 上个界面没有设置navigation title 展示的字是"返回"。设置了title 返回的是上个界面的navigation title
|- _UINavigationBarBackIndicatorView
系统默认的 返回箭头
上面View 均为懒加载 , 而且 除了UINavigationItemView(设置navigation title)的控件为不同的viewController 创建不同的控件,其他view共用,不会重新创建。
设置leftBarButtonItem leftBarButtonItem会替代UINavigationItemButtonView
设置titleView titleView 替代 UINavigationItemView
经常使用的方法
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//修改导航栏背景颜色, 根据self.navigationController.navigationBar.translucent来修改
//如果 translucent false修改_UIBarBackground背景颜色
//如果 translucent true 修改_UIVisualEffectFilterView背景颜色
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
// 修改 UINavigationItemButtonView上title颜色 和 _UINavigationBarBackIndicatorView 返回箭头的颜色
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor blackColor]};
//修改 UINavigationItemButtonView 上title颜色