导航栏
//显示导航栏(两种都可,要互相对应)
self.navigationController.navigationBar.hidden = NO;
self.navigationController.navigationBarHidden = NO;
//隐藏导航栏
self.navigationController.navigationBar.hidden = YES;
self.navigationController.navigationBarHidden = YES;
//YES为透明 NO为不透明
[self.navigationController.navigationBar setTranslucent:NO];
//设置背景颜色
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//设置背景图片
[self.navigationController.navigationBar setBackgroundImage:
[UIImage imageNamed:@"nv_background.png"] forBarMetrics:UIBarMetricsDefault];
//设置标题颜色大小
[[UINavigationBar appearance] setTitleTextAttributes:@{ UITextAttributeTextColor :[UIColor whiteColor],UITextAttributeFont : [UIFont boldSystemFontOfSize:18]}];
//设置导航栏左右按钮颜色大小
[[UIBarButtonItem appearance] setTitleTextAttributes:@{
UITextAttributeTextColor :[UIColor whiteColor],
UITextAttributeFont : [UIFont systemFontOfSize:14]
} forState:UIControlStateNormal];
UINavigationBar *navigationBar = self.navigationController.navigationBar;
//隐藏黑色线条
[navigationBar setShadowImage:[UIImage new]];
//修改线条颜色
[navigationBar setShadowImage:[self imageWithColor:[UIColor redColor] andSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1)]];
//颜色生成图片方法
- (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size
{
CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
状态栏
在plist文件中添加如下键值对Status bar is initially hidden(NO为显示状态栏,YES为隐藏“),View controller-based status bar appearance
//显示
[UIApplication sharedApplication].statusBarHidden = NO;
//隐藏
[UIApplication sharedApplication].statusBarHidden = YES;
//状态栏字体颜色为黑色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];
//状态栏字体颜色为白色
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];