【问题标题】:Status bar color does not match navigation bar状态栏颜色与导航栏不匹配
【发布时间】:2017-01-28 00:02:20
【问题描述】:

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

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

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

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

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

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

navigationController.modalPresentationStyle = UIModalPresentationFormSheet;

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

【问题讨论】:

  • 如何创建导航栏?
  • 视图控制器嵌入在导航控制器中。代码添加到问题。
  • 是的,这就是我想要的样子
  • 好的,我确定问题是由你的错误步骤引起的。我会给出我的步骤来做到这一点。

标签: ios statusbar


【解决方案1】:

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

  1. 如下创建2个视图控制器,你可以让vc1嵌入一个导航控制器:

  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中,你设置标题:

【讨论】:

  • 我发现了问题。有人将此添加到 viewDidLoad 中的方法之一中:self.navigationController.navigationBar.clipsToBounds = true;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-28
  • 2014-02-07
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多