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

Status bar color does not match navigation bar

我有一个模态呈现的视图控制器。我希望状态栏颜色与导航栏颜色匹配。

我已将 UIViewControllerBasedStatusBarAppearance 设置为 YES,因为我不想在整个应用程序中进行此更改。

我正在设置 self.navigationController.navigationBar.barTintColor 但这只是改变了导航栏的颜色。状态栏保持浅色。

我尝试了 setNeedsStatusBarAppearanceUpdate 和 preferredStatusBarStyle 的各种组合,但 none 有任何效果。

视图控制器是这样启动的:

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

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;

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

我的步骤如下,看看哪里错了:

  1. 像下面这样创建2个view controller,你可以让vc1嵌入一个navigation controller:

  1. 在vc1中,你拖一个按钮的动作:

代码如下:

- (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. 然后在vc2中,你设置标题: