1.iOS7之后 要想改变navigationbar的颜色 可以这样子改
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#3A3A3A" alpha:1.0f];
默认带有一定透明效果,可以使用以下方法去除系统效果
[self.navigationController.navigationBar setTranslucent:NO];
2.改变UINavigationBar导航条标题颜色和字体
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1], NSForegroundColorAttributeName,[UIColor colorWithRed:0 green:0.7 blue:0.8 alpha:1],NSShadowAttributeName,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], NSShadowAttributeName,[UIFont fontWithName:@"Arial-Bold" size:0.0], NSFontAttributeName,nil]];
其中 NSForegroundColorAttributeName和NSFontAttributeName 属性是文字颜色和字体
3.改变状态栏的颜色
公司项目需要将状态栏的文字颜色设置为白色,以下方法即可
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
改变后需要及时刷新的调用
[viewController setNeedsStatusBarAppearanceUpdate];
如果没有效果,需要在plist文件里设置
View controller-based status bar appearance = NO
info.plist中 View controller-based status bar appearance这个属性 View controller-based status bar appearance =NO 这个设置为:View Controller 不对status Bar 显示进行操作
4.在某些页面控制navigationbar不显示
在项目中有时候会遇到在有些页面想隐藏navgationbar的情况,只要像这样写就可以了
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}