以支付宝为例!
[self.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[[UIImage alloc] init]];
以上两句话一起,可以将系统的导航栏设置为透明的颜色.如下图-1,相比较常见的系统导航栏,不见了64的那部分内容!---以方便实现支付宝那种偏黑的效果.
//设置bar的tintColor
[self.navigationBar setBarTintColor:[UIColor colorWithHex:0x3a3a3a]];
self.navigationBar.translucent = NO;
实现效果如图-2, 其导航栏的背景色类似于黑色.
//设置所有使用这个导航控制器的vc标题都是白色的 具体内容在navigationController对应的rootViewController中设置
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//修改bar的tintColor 也就是各个item的颜色 如返回等.
[self.navigationBar setTintColor:[UIColor whiteColor]];
具体实现效果如图-3.
************关于是否显示TarBar的方法.
// push控制器的时候调用
- (void)pushViewController:(UIViewController*)viewController animated:(BOOL)animated
{
if (self.viewControllers.count > 0) {
// 只要push控制器 就要隐藏tabbar
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
苹果API文档,关于UIviewController 和UINavigationController的关系,提供一点思路
@interface UIViewController (UINavigationControllerItem)
@property(nonatomic,readonly,strong) UINavigationItem *navigationItem; // Created on-demand so that a view controller may customize its navigation appearance.
@property(nonatomic) BOOL hidesBottomBarWhenPushed __TVOS_PROHIBITED; // If YES, then when this view controller is pushed into a controller hierarchy with a bottom bar (like a tab bar), the bottom bar will slide out. Default is NO.
@property(nullable, nonatomic,readonly,strong) UINavigationController *navigationController; // If this view controller has been pushed onto a navigation controller, return it.
@end