【问题标题】:Status Bar Background Color with Translucent Navigation Bar带有半透明导航栏的状态栏背景颜色
【发布时间】:2016-01-29 22:09:09
【问题描述】:

所以我正在为一个看似简单的问题而苦恼……

我正在尝试使我的应用程序中的状态栏具有背景颜色。现在我遇到的问题是:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

这意味着文本将是白色的。这很好,但是当我运行应用程序并使用它时问题就来了。我在标签栏控制器中嵌入了一个导航控制器(带有表格视图),这样当您向下滚动时,标题就会消失。想想与 facebook、LinkedIn 等类似的功能。

所以现在发生的情况是,当我滚动状态栏时,状态栏是半透明的,带有白色文本......因此无法阅读。

所以我想我可以添加一个子视图如下:

UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
addStatusBar.backgroundColor = [UIColor orangeColor];
[self.window.rootViewController.view addSubview:addStatusBar];

这似乎可行,但颜色不对...所以我不得不关闭导航栏的半透明属性:

self.navigationController.navigationBar.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
self.navigationController.navigationBar.translucent = NO;

这意味着现在颜色保持不变,但它不正确,当我滚动时,您可以看到顶部有一个视图,而不是导航栏“淡入”到顶部的文本(如 Facebook 和 LinkedIn)

我在这里缺少什么?有没有办法访问statusBar.backgroundColor??

感谢您的帮助。

一个

【问题讨论】:

  • 也许你应该分享隐藏导航栏的代码? Facebook 只是淡化导航栏项目并将导航栏从屏幕上移出 20 点。没有公共 API 可以更改状态栏背景颜色。
  • 我所做的隐藏是内置的:self.navigationController.hidesBarsOnSwipe = YES;

标签: ios objective-c iphone ios8 ios9


【解决方案1】:

您不会在 plist 中找到“UIViewControllerBasedStatusBarAppearance”属性,但默认情况下它不存在。您必须通过单击 + 按钮自行添加,然后将其设置为“否”。

添加到 .plist 后,你必须去你的 AppDelegate.m 文件并在 didFinishLaunchingWithOptions 方法中添加以下内容,添加以下代码行:

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    UIView *addStatusBar = [[UIView alloc] init];
    addStatusBar.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 20);
    addStatusBar.backgroundColor = [UIColor orangeColor];

YourViewController *vc = (YourViewController *)[storyboard instantiateViewControllerWithIdentifier:@“YourViewController"];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:vc];

self.window.rootViewController = tabBarControllerObj;
[self.window.rootViewController.view addSubview:addStatusBar];

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2021-09-27
    相关资源
    最近更新 更多