StatusBar/NavigationBar

参考文档1
参考文档2
参考文档3
参考文档

状态栏颜色分为两种:
UIStatusBarStyleDefault 黑色
UIStatusBarStyleLightContent 白色

设置状态栏颜色 :

前景色

方法A:

  1. info.plist 中
    View controller-based status bar appearance 设为 NO
  2. AppDelegate中
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  3. 个别VC状态栏修改
- (void)viewWillAppear:(BOOL)animated{
   [super viewWillAppear:animated]
   [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
-(void)viewWillDisappear:(BOOL)animated{
   [super viewWillDisappear:animated];
   [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

方法 B:
1、plist
View controller-based status bar appearance 设置为 YES
注意:View controller-based status bar appearance为YES时[UIApplication sharedApplication].statusBarStyle 无效。

  1. 代码
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

背景色

方法 A: 系统方法

self.navigationController.navigationBar.barTintColor = [UIColor greenColor];

//如果想将状态栏和导航栏字体全变为白色
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

//如果只想改变导航栏的字体颜色大小
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:25]}];

//或者可以设置背景图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"image"] forBarMetrics:UIBarMetricsDefault];

导航栏颜色

//Baritem 颜色
[UINavigationBar appearance].tintColor = [UIColor orangeColor];

//调整导航栏背景图片
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"m_nav64"] forBarMetrics:UIBarMetricsDefault];
 //调整导航栏背景色
[UINavigationBar appearance].barTintColor = [UIColor orangeColor];
    
//半透明开关    
self.navigationController.navigationBar.translucent = NO;
    
//为导航栏添加背景图片,图片如果是44高,那么不覆盖状态栏,
//如果是64高就会覆盖状态栏
//UIBarMetricsDefault 缺省值
//UIBarMetricsCompact 横屏样式 
//UIBarMetricsDefaultPrompt和UIBarMetricsCompactPrompt是有promt的两种样式
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"m_nav64"] forBarMetrics:UIBarMetricsDefault];
    
//修改导航栏标题的字体
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
    
//字典中放入你想修改的键值对,原来的UITextAttributeFont、UITextAttributeTextColor、UITextAttributeTextShadowColor、UITextAttributeTextShadowOffset已弃用
self.navigationController.navigationBar.titleTextAttributes 
= 
@{NSForegroundColorAttributeName:[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0],
  NSShadowAttributeName:shadow,
  NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0]
 };
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容