iOS状态栏和导航栏的设置

状态栏设置为白色

在info.plist文件中设置:

  1. View controller-based status bar appearance 为NO
  2. Status bar style 为 Opaque black style
    配置如下图:
    info.plist

** 注意: **这么设置后,会导致横屏状态下状态栏消失,所以可以采取下面的方式(删除上面2个配置的属性),新建一个UIViewController的基类,然后重写它的prefersStatusBarHidden方法和preferredStatusBarStyle方法,如下:

- (BOOL)prefersStatusBarHidden {
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

iOS横屏状态栏不显示解决办法:
1.在plist文件中将View controller-based status bar appearance设置为NO
2.在application:didFinishLaunchingWithOptions:中添加下面代码:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; 

导航栏设置颜色

[[UINavigationBar appearance] setBarTintColor:[UIColor purpleColor]];

设置UIBarButtonItem的颜色

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

设置导航栏的字体

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont systemFontOfSize:18]}];

设置导航栏返回键的标题

    //在上一级VC中添加如下代码
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"";
    self.navigationItem.backBarButtonItem = backItem;

你可能感兴趣的:(iOS状态栏和导航栏的设置)