简体   繁体   English

状态栏颜色与导航栏不匹配

[英]Status bar color does not match navigation bar

I have a view controller I am presenting modally. 我有一个模态呈现的视图控制器。 I want the status bar color to match the navigation bar color. 我希望状态栏颜色与导航栏颜色匹配。

I have set UIViewControllerBasedStatusBarAppearance to YES because I don't want this change across the entire application. 我将UIViewControllerBasedStatusBarAppearance设置为YES,因为我不希望在整个应用程序中进行此更改。

I am setting self.navigationController.navigationBar.barTintColor but this is only changing the navigation bar color. 我正在设置self.navigationController.navigationBar.barTintColor,但这只是更改导航栏的颜色。 The status bar remains a lighter color. 状态栏保持较浅的颜色。

I have tried various combinations of setNeedsStatusBarAppearanceUpdate and preferredStatusBarStyle but none have any effect. 我已经尝试过setNeedsStatusBarAppearanceUpdate和preferredStatusBarStyle的各种组合,但是没有任何作用。

在此处输入图片说明

View controller is launched like so: View Controller的启动方式如下:

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:searchController];

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentViewController:navigationController animated:YES completion:nil];

My steps are below, check where you go wrong: 我的步骤如下,请检查您出了什么问题:

  1. Create 2 view controller like below, you can let vc1 embed in a navigation controller: 创建2个如下所示的视图控制器,您可以将vc1嵌入导航控制器中:

在此处输入图片说明

  1. In the vc1, you drag a action of the button: 在vc1中,拖动按钮的操作:

在此处输入图片说明

Code is below: 代码如下:

- (IBAction)clickAction:(UIButton *)sender {

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController2 *searchController = [sb instantiateViewControllerWithIdentifier:@"ViewController2"];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:searchController];

    navigationController.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentViewController:navigationController animated:YES completion:nil];
}
  1. Then in the vc2, you set the title: 然后在vc2中,设置标题:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM